From a489e86e994eee3f1bc5fae389887fa7c5eee29c Mon Sep 17 00:00:00 2001 From: DavidBluecame Date: Fri, 29 Jan 2016 15:55:22 +0100 Subject: [PATCH] Attempt to fix some crashes when adjusting material parameters Sometimes I'm getting crashes when changing material parameters or when switching tabs in the object properties panel in Blender. This is an old issue and I tried several changes, but still happens. I don't know if this is caused by some thread/concurrency problem or by deleting objects already deleted for some reason. Just in case I'm doing some changes to try to avoid this. I hope they help and don't cause any other problems like memory leaks, etc. --- src/bindings/yafrayinterface.i | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/bindings/yafrayinterface.i b/src/bindings/yafrayinterface.i index 25d28300..fdfad180 100755 --- a/src/bindings/yafrayinterface.i +++ b/src/bindings/yafrayinterface.i @@ -175,6 +175,9 @@ public: virtual void initTilesPasses(int totalViews, int numExtPasses) { + PyGILState_STATE gstate; + gstate = PyGILState_Ensure(); + tilesPasses.resize(totalViews); for(size_t view = 0; view < tilesPasses.size(); ++view) @@ -188,20 +191,27 @@ public: tilesPasses.at(view)[idx]->resy = resy; } } + + PyGILState_Release(gstate); } virtual ~pyOutput_t() { + PyGILState_STATE gstate; + gstate = PyGILState_Ensure(); + for(size_t view = 0; view < tilesPasses.size(); ++view) { for(size_t idx = 0; idx < tilesPasses.at(view).size(); ++idx) { - delete [] tilesPasses.at(view)[idx]->mem; + if(tilesPasses.at(view)[idx]->mem) delete [] tilesPasses.at(view)[idx]->mem; //Py_XDECREF(tilesPasses.at(view)[idx]); } tilesPasses.at(view).clear(); } tilesPasses.clear(); + + PyGILState_Release(gstate); } virtual bool putPixel(int numView, int x, int y, const yafaray::renderPasses_t *renderPasses, const std::vector &colExtPasses, bool alpha = true)