From 5261e209e610b793ba5133d4900fe689ee8067c9 Mon Sep 17 00:00:00 2001 From: Gabriel Studer <gabriel.studer@unibas.ch> Date: Thu, 26 Sep 2013 10:56:21 +0200 Subject: [PATCH] fix another segfault on exit --- modules/gfx/pymod/export_scene.cc | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/modules/gfx/pymod/export_scene.cc b/modules/gfx/pymod/export_scene.cc index 06e81223e..ba8274d37 100644 --- a/modules/gfx/pymod/export_scene.cc +++ b/modules/gfx/pymod/export_scene.cc @@ -87,6 +87,9 @@ void scene_set_hemi_p(Scene* s, tuple p) } // anon ns +void clear_scene() { + Scene::Instance().RemoveAll(); +} void export_Scene() { @@ -264,4 +267,16 @@ void export_Scene() .add_property("show_export_aspect",&Scene::GetShowExportAspect,&Scene::SetShowExportAspect) .add_property("hemi_params",scene_get_hemi_p,scene_set_hemi_p) ; + + // we need to make sure there are no pending references to Python objects + // tied to the scene singleton. The destructor of + // scene may be called after Python is shutdown which results + // in a segfault. + scope().attr("__dict__")["atexit"]=handle<>(PyImport_ImportModule("atexit")); + + def("_clear_scene", &clear_scene); + object r=scope().attr("_clear_scene"); + scope().attr("atexit").attr("register")(r); + } + -- GitLab