Fix T51877: Deleting a scene uses freed memory

At the moment libblock_remap_data_preprocess is using
FOREACH_SCENE_OBJECT to iterate over all the objects of the scene and
unlink them.

However we were storing a reference to the Base of the removed object.
Anyways, the loop is now sanitized so that this crash no longer happens.

Also now we have an unittest for this.
This commit is contained in:
Dalai Felinto 2017-06-30 18:59:29 +02:00
parent b43cdc91ce
commit 49a35033be
Notes: blender-bot 2023-02-14 10:18:56 +01:00
Referenced by issue #51877, 2.8: Deleting a scene uses freed memory
Referenced by issue #51878, 2.8: Deleting a objects uses freed memory
3 changed files with 45 additions and 5 deletions

View File

@ -565,7 +565,7 @@ void BKE_scene_collections_iterator_end(struct BLI_Iterator *iter)
typedef struct SceneObjectsIteratorData {
GSet *visited;
LinkData *link;
LinkData *link_next;
BLI_Iterator scene_collection_iter;
} SceneObjectsIteratorData;
@ -609,10 +609,10 @@ static LinkData *object_base_unique(GSet *gs, LinkData *link)
void BKE_scene_objects_iterator_next(BLI_Iterator *iter)
{
SceneObjectsIteratorData *data = iter->data;
LinkData *link = data->link ? object_base_unique(data->visited, data->link->next) : NULL;
LinkData *link = data->link_next ? object_base_unique(data->visited, data->link_next) : NULL;
if (link) {
data->link = link;
data->link_next = link->next;
iter->current = link->data;
}
else {
@ -624,8 +624,8 @@ void BKE_scene_objects_iterator_next(BLI_Iterator *iter)
/* get the first unique object of this collection */
LinkData *new_link = object_base_unique(data->visited, sc->objects.first);
if (new_link) {
data->link = new_link;
iter->current = data->link->data;
data->link_next = new_link->next;
iter->current = new_link->data;
return;
}
BKE_scene_collections_iterator_next(&data->scene_collection_iter);

View File

@ -170,4 +170,5 @@ RENDER_LAYER_TEST(scene_copy_b)
RENDER_LAYER_TEST(scene_copy_c)
RENDER_LAYER_TEST(scene_copy_d)
RENDER_LAYER_TEST(scene_copy_e)
RENDER_LAYER_TEST(scene_delete)
RENDER_LAYER_TEST(scene_write_read)

View File

@ -0,0 +1,39 @@
# ############################################################
# Importing - Same For All Render Layer Tests
# ############################################################
import unittest
import os
import sys
from render_layer_common import *
# ############################################################
# Testing
# ############################################################
class UnitTesting(RenderLayerTesting):
def test_scene_delete(self):
"""
See if a scene can be properly deleted
"""
import bpy
scene = bpy.context.scene
bpy.data.scenes.new('New')
bpy.data.scenes.remove(scene)
# ############################################################
# Main - Same For All Render Layer Tests
# ############################################################
if __name__ == '__main__':
import sys
extra_arguments = sys.argv[sys.argv.index("--") + 1:] if "--" in sys.argv else []
sys.argv = [__file__] + (sys.argv[sys.argv.index("--") + 2:] if "--" in sys.argv else [])
UnitTesting._extra_arguments = extra_arguments
unittest.main()