diff --git a/source/blender/yafray/intern/export_Plugin.cpp b/source/blender/yafray/intern/export_Plugin.cpp index 5d58612bc4d..6dd14343830 100644 --- a/source/blender/yafray/intern/export_Plugin.cpp +++ b/source/blender/yafray/intern/export_Plugin.cpp @@ -93,8 +93,7 @@ static string YafrayPath() { #ifdef WIN32 string path=find_path(); - return path; - + return path; #else static char *alternative[]= { @@ -105,10 +104,10 @@ static string YafrayPath() for(int i=0;alternative[i]!=NULL;++i) { - string fp=string(alternative[i])+"libyafrayplugin.so"; + string fp = string(alternative[i]) + "libyafrayplugin.so"; struct stat st; - if(stat(fp.c_str(),&st)<0) continue; - if(st.st_mode&S_IROTH) return fp; + if (stat(fp.c_str(), &st)<0) continue; + if (st.st_mode & S_IROTH) return fp; } return ""; #endif @@ -129,8 +128,8 @@ static string YafrayPluginPath() for(int i=0;alternative[i]!=NULL;++i) { struct stat st; - if(stat(alternative[i],&st)<0) continue; - if(S_ISDIR(st.st_mode) && (st.st_mode&S_IXOTH)) return alternative[i]; + if (stat(alternative[i], &st)<0) continue; + if (S_ISDIR(st.st_mode) && (st.st_mode & S_IXOTH)) return alternative[i]; } return ""; #endif @@ -140,59 +139,64 @@ static string YafrayPluginPath() yafrayPluginRender_t::~yafrayPluginRender_t() { - if(yafrayGate!=NULL) delete yafrayGate; - if(handle!=NULL) PIL_dynlib_close(handle); + if (yafrayGate!=NULL) delete yafrayGate; + if (handle!=NULL) PIL_dynlib_close(handle); #ifdef WIN32 - if(corehandle!=NULL) PIL_dynlib_close(corehandle); + if (corehandle!=NULL) PIL_dynlib_close(corehandle); #endif } bool yafrayPluginRender_t::initExport() { - if(handle==NULL) + // bug #1897: when forcing render without yafray present, handle can be valid, + // but find_symbol might have failed, trying second time will crash. + // So make sure plugin loaded correctly and only get handle once. + if ((!plugin_loaded) || (handle==NULL)) { - string location=YafrayPath(); + string location = YafrayPath(); #ifdef WIN32 /* Win 32 loader cannot find needed libs in yafray dir, so we have to load them * by hand. This could be fixed using setdlldirectory function, but it is not * available in all win32 versions */ - corehandle=PIL_dynlib_open((char *)(location+"\\yafraycore.dll").c_str()); - if(corehandle==NULL) + corehandle = PIL_dynlib_open((char *)(location + "\\yafraycore.dll").c_str()); + if (corehandle==NULL) { - cerr<<"Error loading yafray plugin: "<