Fix #34121: OSL + persistent images option was not freeing shader memory properly,
[blender.git] / intern / cycles / render / osl.cpp
index 28de56f3a727a96c7d4a96b412c5a761bd5c901d..56158278e29e8593ac2606a9da27e1cb0f2bf603 100644 (file)
@@ -47,15 +47,25 @@ OSLShaderManager::OSLShaderManager()
 {
        services = new OSLRenderServices();
 
-       shading_system_init();
        texture_system_init();
+       shading_system_init();
 }
 
 OSLShaderManager::~OSLShaderManager()
 {
        OSL::ShadingSystem::destroy(ss);
        OSL::TextureSystem::destroy(ts);
+
+       delete services;
+}
+
+void OSLShaderManager::reset(Scene *scene)
+{
+       OSL::ShadingSystem::destroy(ss);
        delete services;
+
+       services = new OSLRenderServices();
+       shading_system_init();
 }
 
 void OSLShaderManager::device_update(Device *device, DeviceScene *dscene, Scene *scene, Progress& progress)
@@ -88,6 +98,7 @@ void OSLShaderManager::device_update(Device *device, DeviceScene *dscene, Scene
        og->ss = ss;
        og->ts = ts;
        og->services = services;
+
        int background_id = scene->shader_manager->get_shader_id(scene->default_background);
        og->background_state = og->surface_state[background_id & SHADER_MASK];
        og->use = true;