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:
Lukas Stockner
2016-05-08 01:44:01 +02:00
parent 6100c2d262
commit cbaa25eb88
5 changed files with 15 additions and 20 deletions

View File

@@ -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)