Fix #33405: preview render getting stuck in a particular .blend file, ObjectKey
authorBrecht Van Lommel <brechtvanlommel@pandora.be>
Tue, 4 Dec 2012 07:48:09 +0000 (07:48 +0000)
committerBrecht Van Lommel <brechtvanlommel@pandora.be>
Tue, 4 Dec 2012 07:48:09 +0000 (07:48 +0000)
operator< had wrong brackets, changed it now to be more clear.

Fix #33404: crash GPU rendering with OSL option still enabled. There was a check
to disable OSL in this case, but it shouldn't have modified scene->params because
this is used for comparison in scene->modified().

intern/cycles/blender/blender_shader.cpp
intern/cycles/blender/blender_util.h
intern/cycles/kernel/kernel_shader.h
intern/cycles/render/mesh.cpp
intern/cycles/render/osl.h
intern/cycles/render/scene.cpp
intern/cycles/render/shader.cpp
intern/cycles/render/shader.h

index da06f1d0a38b9e14babb8930383aac795abf095e..c9380d8d58be5f10ba4c0de47dbd3be1a32dfe1a 100644 (file)
@@ -445,7 +445,7 @@ static ShaderNode *add_node(Scene *scene, BL::BlendData b_data, BL::Scene b_scen
                }
                case BL::ShaderNode::type_SCRIPT: {
 #ifdef WITH_OSL
-                       if(scene->params.shadingsystem != SceneParams::OSL)
+                       if(!scene->shader_manager->use_osl())
                                break;
 
                        /* create script node */
index 4feb8b556d5ca7d01b08d08d2bbd8d3c866cb889..0a9f2dd06aa20005583b411f5fefb92d06c0934a 100644 (file)
@@ -367,12 +367,22 @@ struct ObjectKey {
 
        bool operator<(const ObjectKey& k) const
        {
-               return (parent < k.parent) ||
-                      (parent == k.parent && (memcmp(id, k.id, sizeof(id)) < 0)) ||
-                      (memcmp(id, k.id, sizeof(id)) == 0 && ob < k.ob);
+               if(ob < k.ob) {
+                       return true;
+               }
+               else if(ob == k.ob) {
+                       if(parent < k.parent)
+                               return true;
+                       else if(parent == k.parent)
+                               return memcmp(id, k.id, sizeof(id)) < 0;
+               }
+
+               return false;
        }
 };
 
+/* Particle System Key */
+
 struct ParticleSystemKey {
        void *ob;
        int id[OBJECT_PERSISTENT_ID_SIZE];
@@ -389,8 +399,12 @@ struct ParticleSystemKey {
        bool operator<(const ParticleSystemKey& k) const
        {
                /* first id is particle index, we don't compare that */
-               return (ob < k.ob) ||
-                      (ob == k.ob && (memcmp(id+1, k.id+1, sizeof(int)*(OBJECT_PERSISTENT_ID_SIZE-1)) < 0));
+               if(ob < k.ob)
+                       return true;
+               else if(ob == k.ob)
+                       return memcmp(id+1, k.id+1, sizeof(int)*(OBJECT_PERSISTENT_ID_SIZE-1)) < 0;
+
+               return false;
        }
 };
 
index 43ad4b1265abbed7621ca9209c6c556e9ba91733..98a7ec59d7b866e729e5839843db483612a12ea8 100644 (file)
@@ -698,7 +698,7 @@ __device void shader_eval_surface(KernelGlobals *kg, ShaderData *sd,
 #ifdef __SVM__
                svm_eval_nodes(kg, sd, SHADER_TYPE_SURFACE, randb, path_flag);
 #else
-               bsdf_diffuse_setup(sd, &sd->closure);
+               bsdf_diffuse_setup(&sd->closure);
                sd->closure.weight = make_float3(0.8f, 0.8f, 0.8f);
 #endif
        }
index 1958cfc10f7d1721121952e1c658a6d5d787393f..bc782a78c60648b6bf98cfad063e6b67d29cb2e3 100644 (file)
@@ -547,7 +547,7 @@ void MeshManager::device_update_attributes(Device *device, DeviceScene *dscene,
        }
 
        /* create attribute lookup maps */
-       if(scene->params.shadingsystem == SceneParams::OSL)
+       if(scene->shader_manager->use_osl())
                update_osl_attributes(device, scene, mesh_attributes);
        else
                update_svm_attributes(device, dscene, scene, mesh_attributes);
index 08b5f8b89fbee48f507c0efbb9d6b6eb11eb30f0..9b58745bd46bffa587e1b7a6e55ee995b82d80f9 100644 (file)
@@ -52,6 +52,8 @@ public:
        OSLShaderManager();
        ~OSLShaderManager();
 
+       bool use_osl() { return true; }
+
        void device_update(Device *device, DeviceScene *dscene, Scene *scene, Progress& progress);
        void device_free(Device *device, DeviceScene *dscene);
 
index 7834aa701eaef5b1ace9c3175242509f6b267c07..8085cfdd3e6a23dbc31d436daf1205ac92368390 100644 (file)
@@ -44,10 +44,6 @@ Scene::Scene(const SceneParams& params_, const DeviceInfo& device_info_)
        device = NULL;
        memset(&dscene.data, 0, sizeof(dscene.data));
 
-       /* OSL only works on the CPU */
-       if(device_info_.type != DEVICE_CPU)
-               params.shadingsystem = SceneParams::SVM;
-
        camera = new Camera();
        filter = new Filter();
        film = new Film();
@@ -57,9 +53,14 @@ Scene::Scene(const SceneParams& params_, const DeviceInfo& device_info_)
        object_manager = new ObjectManager();
        integrator = new Integrator();
        image_manager = new ImageManager();
-       shader_manager = ShaderManager::create(this);
        particle_system_manager = new ParticleSystemManager();
 
+       /* OSL only works on the CPU */
+       if(device_info_.type == DEVICE_CPU)
+               shader_manager = ShaderManager::create(this, params.shadingsystem);
+       else
+               shader_manager = ShaderManager::create(this, SceneParams::SVM);
+
        if (device_info_.type == DEVICE_CPU)
                image_manager->set_extended_image_limits();
 }
index 17f7fbd43d656fa69c289c700782f3a71f26ed0b..b9b49bf29896f6a37cbbfe5ab6f7ea2599236652 100644 (file)
@@ -121,12 +121,12 @@ ShaderManager::~ShaderManager()
 {
 }
 
-ShaderManager *ShaderManager::create(Scene *scene)
+ShaderManager *ShaderManager::create(Scene *scene, int shadingsystem)
 {
        ShaderManager *manager;
 
 #ifdef WITH_OSL
-       if(scene->params.shadingsystem == SceneParams::OSL)
+       if(shadingsystem == SceneParams::OSL)
                manager = new OSLShaderManager();
        else
 #endif
index 373b3356f51dc88653f88aa8b71d3a6907ee8d1f..d4421002cebc0e6e246ecf7f4a54d0f691ecf465 100644 (file)
@@ -107,9 +107,11 @@ class ShaderManager {
 public:
        bool need_update;
 
-       static ShaderManager *create(Scene *scene);
+       static ShaderManager *create(Scene *scene, int shadingsystem);
        virtual ~ShaderManager();
 
+       virtual bool use_osl() { return false; }
+
        /* device update */
        virtual void device_update(Device *device, DeviceScene *dscene, Scene *scene, Progress& progress) = 0;
        virtual void device_free(Device *device, DeviceScene *dscene) = 0;