Cycles: Fix two small memory leaks and deduplicate table freeing
This commit makes remove_table skip the freeing if the offset is already set to invalid - or, if it wasn't, set it to invalid after freeing. That's what the current code was already doing in the Manager classes, this change allows them to just call remove without the additional code. Also, two potential memory leaks where new tables were always allocated without freeing the old ones are fixed. Reviewers: sergey, dingto, brecht Differential Revision: https://developer.blender.org/D1974
This commit is contained in:
parent
6100c2d262
commit
cbaa25eb88
Notes:
blender-bot
2023-02-14 07:51:32 +01:00
Referenced by issue #48525, Blender Crashes when using Motion Blur, more than one Layer and Animated Camera while Rendering in Cycles
|
@ -323,6 +323,7 @@ void Camera::device_update(Device *device, DeviceScene *dscene, Scene *scene)
|
|||
#ifdef __CAMERA_MOTION__
|
||||
kcam->shuttertime = (need_motion == Scene::MOTION_BLUR) ? shuttertime: -1.0f;
|
||||
|
||||
scene->lookup_tables->remove_table(&shutter_table_offset);
|
||||
if(need_motion == Scene::MOTION_BLUR) {
|
||||
vector<float> shutter_table;
|
||||
util_cdf_inverted(SHUTTER_TABLE_SIZE,
|
||||
|
@ -335,10 +336,6 @@ void Camera::device_update(Device *device, DeviceScene *dscene, Scene *scene)
|
|||
shutter_table);
|
||||
kcam->shutter_table_offset = (int)shutter_table_offset;
|
||||
}
|
||||
else if(shutter_table_offset != TABLE_OFFSET_INVALID) {
|
||||
scene->lookup_tables->remove_table(shutter_table_offset);
|
||||
shutter_table_offset = TABLE_OFFSET_INVALID;
|
||||
}
|
||||
#else
|
||||
kcam->shuttertime = -1.0f;
|
||||
#endif
|
||||
|
@ -425,10 +422,7 @@ void Camera::device_free(Device * /*device*/,
|
|||
DeviceScene * /*dscene*/,
|
||||
Scene *scene)
|
||||
{
|
||||
if(shutter_table_offset != TABLE_OFFSET_INVALID) {
|
||||
scene->lookup_tables->remove_table(shutter_table_offset);
|
||||
shutter_table_offset = TABLE_OFFSET_INVALID;
|
||||
}
|
||||
scene->lookup_tables->remove_table(&shutter_table_offset);
|
||||
}
|
||||
|
||||
bool Camera::modified(const Camera& cam)
|
||||
|
|
|
@ -428,6 +428,7 @@ void Film::device_update(Device *device, DeviceScene *dscene, Scene *scene)
|
|||
|
||||
/* update filter table */
|
||||
vector<float> table = filter_table(filter_type, filter_width);
|
||||
scene->lookup_tables->remove_table(&filter_table_offset);
|
||||
filter_table_offset = scene->lookup_tables->add_table(dscene, table);
|
||||
kfilm->filter_table_offset = (int)filter_table_offset;
|
||||
|
||||
|
@ -443,10 +444,7 @@ void Film::device_free(Device * /*device*/,
|
|||
DeviceScene * /*dscene*/,
|
||||
Scene *scene)
|
||||
{
|
||||
if(filter_table_offset != TABLE_OFFSET_INVALID) {
|
||||
scene->lookup_tables->remove_table(filter_table_offset);
|
||||
filter_table_offset = TABLE_OFFSET_INVALID;
|
||||
}
|
||||
scene->lookup_tables->remove_table(&filter_table_offset);
|
||||
}
|
||||
|
||||
bool Film::modified(const Film& film)
|
||||
|
|
|
@ -404,8 +404,8 @@ void ShaderManager::device_update_common(Device *device,
|
|||
}
|
||||
}
|
||||
beckmann_table_offset = scene->lookup_tables->add_table(dscene, beckmann_table);
|
||||
ktables->beckmann_offset = (int)beckmann_table_offset;
|
||||
}
|
||||
ktables->beckmann_offset = (int)beckmann_table_offset;
|
||||
|
||||
/* integrator */
|
||||
KernelIntegrator *kintegrator = &dscene->data.integrator;
|
||||
|
@ -418,10 +418,7 @@ void ShaderManager::device_update_common(Device *device,
|
|||
|
||||
void ShaderManager::device_free_common(Device *device, DeviceScene *dscene, Scene *scene)
|
||||
{
|
||||
if(beckmann_table_offset != TABLE_OFFSET_INVALID) {
|
||||
scene->lookup_tables->remove_table(beckmann_table_offset);
|
||||
beckmann_table_offset = TABLE_OFFSET_INVALID;
|
||||
}
|
||||
scene->lookup_tables->remove_table(&beckmann_table_offset);
|
||||
|
||||
device->tex_free(dscene->shader_flag);
|
||||
dscene->shader_flag.clear();
|
||||
|
|
|
@ -94,15 +94,21 @@ size_t LookupTables::add_table(DeviceScene *dscene, vector<float>& data)
|
|||
return new_table.offset;
|
||||
}
|
||||
|
||||
void LookupTables::remove_table(size_t offset)
|
||||
void LookupTables::remove_table(size_t *offset)
|
||||
{
|
||||
if(*offset == TABLE_OFFSET_INVALID) {
|
||||
/* The table isn't even allocated, so just return here. */
|
||||
return;
|
||||
}
|
||||
|
||||
need_update = true;
|
||||
|
||||
list<Table>::iterator table;
|
||||
|
||||
for(table = lookup_tables.begin(); table != lookup_tables.end(); table++) {
|
||||
if(table->offset == offset) {
|
||||
if(table->offset == *offset) {
|
||||
lookup_tables.erase(table);
|
||||
*offset = TABLE_OFFSET_INVALID;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -45,7 +45,7 @@ public:
|
|||
void device_free(Device *device, DeviceScene *dscene);
|
||||
|
||||
size_t add_table(DeviceScene *dscene, vector<float>& data);
|
||||
void remove_table(size_t offset);
|
||||
void remove_table(size_t *offset);
|
||||
};
|
||||
|
||||
CCL_NAMESPACE_END
|
||||
|
|
Loading…
Reference in New Issue