Fix Freestyle (ASAN detected) crash

This was very simple to reproduce, just turn on Freestyle and press render.

Now to the truth of things. Most (if not all) of
~BlenderStrokeRenderer() can be removed. I believe this was done back
when freestyle was using G.main, and since we gave freestyle its own
main we can just leave the cleanup for later.

I will leave this for freestyle maintainers to think over though.

Note: There is a chance this was the issue reported on T57890. I will
wait for the reporter to confirm this as fixed though.
This commit is contained in:
Dalai Felinto
2019-01-25 14:54:36 -02:00
parent da6bda6483
commit fa1d5586a1

View File

@@ -185,10 +185,11 @@ BlenderStrokeRenderer::~BlenderStrokeRenderer()
// compositor has finished.
// release objects and data blocks
Base *base_next = NULL;
ViewLayer *view_layer = (ViewLayer *)freestyle_scene->view_layers.first;
for (Base *b = (Base *)view_layer->object_bases.first; b; b = b->next) {
for (Base *b = (Base *)view_layer->object_bases.first; b; b = base_next) {
base_next = b->next;
Object *ob = b->object;
void *data = ob->data;
char *name = ob->id.name;
#if 0
if (G.debug & G_DEBUG_FREESTYLE) {
@@ -196,23 +197,20 @@ BlenderStrokeRenderer::~BlenderStrokeRenderer()
}
#endif
switch (ob->type) {
case OB_MESH:
BKE_id_free(freestyle_bmain, ob);
BKE_id_free(freestyle_bmain, data);
break;
case OB_CAMERA:
BKE_id_free(freestyle_bmain, ob);
BKE_id_free(freestyle_bmain, data);
freestyle_scene->camera = NULL;
ATTR_FALLTHROUGH;
case OB_MESH:
BKE_scene_collections_object_remove(freestyle_bmain,
freestyle_scene,
ob,
true);
break;
default:
cerr << "Warning: unexpected object in the scene: " << name[0] << name[1] << ":" << (name + 2) << endl;
}
}
// Make sure we don't have any bases which might reference freed objects.
BKE_main_collection_sync(freestyle_bmain);
// release materials
Link *lnk = (Link *)freestyle_bmain->mat.first;