[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [55792] trunk/blender/intern/cycles/render : Fix #34601: cycles OSL crash when using preview render and viewport render at
Brecht Van Lommel
brechtvanlommel at pandora.be
Fri Apr 5 01:48:08 CEST 2013
Revision: 55792
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=55792
Author: blendix
Date: 2013-04-04 23:48:07 +0000 (Thu, 04 Apr 2013)
Log Message:
-----------
Fix #34601: cycles OSL crash when using preview render and viewport render at
the same time, due to shared texture cache system.
Modified Paths:
--------------
trunk/blender/intern/cycles/render/osl.cpp
trunk/blender/intern/cycles/render/osl.h
Modified: trunk/blender/intern/cycles/render/osl.cpp
===================================================================
--- trunk/blender/intern/cycles/render/osl.cpp 2013-04-04 23:16:23 UTC (rev 55791)
+++ trunk/blender/intern/cycles/render/osl.cpp 2013-04-04 23:48:07 UTC (rev 55792)
@@ -41,6 +41,12 @@
#ifdef WITH_OSL
+/* Shared Texture System */
+
+OSL::TextureSystem *OSLShaderManager::ts_shared = NULL;
+int OSLShaderManager::ts_shared_users = 0;
+thread_mutex OSLShaderManager::ts_shared_mutex;
+
/* Shader Manager */
OSLShaderManager::OSLShaderManager()
@@ -54,8 +60,18 @@
OSLShaderManager::~OSLShaderManager()
{
OSL::ShadingSystem::destroy(ss);
- OSL::TextureSystem::destroy(ts);
+ /* shared texture system decrease users and destroy if no longer used */
+ {
+ thread_scoped_lock lock(ts_shared_mutex);
+ ts_shared_users--;
+
+ if(ts_shared_users == 0) {
+ OSL::TextureSystem::destroy(ts_shared);
+ ts_shared = NULL;
+ }
+ }
+
delete services;
}
@@ -133,14 +149,22 @@
void OSLShaderManager::texture_system_init()
{
- /* if we let OSL create it, it leaks */
- ts = TextureSystem::create(true);
- ts->attribute("automip", 1);
- ts->attribute("autotile", 64);
- ts->attribute("gray_to_rgb", 1);
+ /* create texture system, shared between different renders to reduce memory usage */
+ thread_scoped_lock lock(ts_shared_mutex);
- /* effectively unlimited for now, until we support proper mipmap lookups */
- ts->attribute("max_memory_MB", 16384);
+ if(ts_shared_users == 0) {
+ ts_shared = TextureSystem::create(true);
+
+ ts_shared->attribute("automip", 1);
+ ts_shared->attribute("autotile", 64);
+ ts_shared->attribute("gray_to_rgb", 1);
+
+ /* effectively unlimited for now, until we support proper mipmap lookups */
+ ts_shared->attribute("max_memory_MB", 16384);
+ }
+
+ ts = ts_shared;
+ ts_shared_users++;
}
void OSLShaderManager::shading_system_init()
Modified: trunk/blender/intern/cycles/render/osl.h
===================================================================
--- trunk/blender/intern/cycles/render/osl.h 2013-04-04 23:16:23 UTC (rev 55791)
+++ trunk/blender/intern/cycles/render/osl.h 2013-04-04 23:48:07 UTC (rev 55792)
@@ -21,6 +21,7 @@
#include "util_set.h"
#include "util_string.h"
+#include "util_thread.h"
#include "shader.h"
@@ -92,6 +93,10 @@
OSLRenderServices *services;
OSL::ErrorHandler errhandler;
map<string, OSLShaderInfo> loaded_shaders;
+
+ static OSL::TextureSystem *ts_shared;
+ static thread_mutex ts_shared_mutex;
+ static int ts_shared_users;
};
#endif
More information about the Bf-blender-cvs
mailing list