Lamps should not have their own gpu material
authorDalai Felinto <dfelinto@gmail.com>
Tue, 11 Jul 2017 09:00:46 +0000 (11:00 +0200)
committerDalai Felinto <dfelinto@gmail.com>
Tue, 11 Jul 2017 09:02:56 +0000 (11:02 +0200)
This was leading to multiple crashes when freeing the lamps or
materials when opening old files.

Follow up on b50839038d6b3d2.

source/blender/gpu/intern/gpu_lamp.c
source/blender/gpu/intern/gpu_lamp_private.h
source/blender/gpu/intern/gpu_material.c

index 12b9eaf22f88ce47c4e533b08de47829ea7447fc..8bf343568b12daad70e63f7e9a09c88fea7e8f64 100644 (file)
@@ -386,21 +386,10 @@ void GPU_lamp_free(Object *ob)
 {
        GPULamp *lamp;
        LinkData *link;
-       LinkData *nlink;
-       Material *ma;
 
        for (link = ob->gpulamp.first; link; link = link->next) {
                lamp = link->data;
 
-               while (lamp->materials.first) {
-                       nlink = lamp->materials.first;
-                       ma = nlink->data;
-                       BLI_freelinkN(&lamp->materials, nlink);
-
-                       if (ma->gpumaterial.first)
-                               GPU_material_free(&ma->gpumaterial);
-               }
-
                gpu_lamp_shadow_free(lamp);
                GPU_lamp_engine_data_free(&lamp->data);
 
index ef71385e66d06c541b1b57d3f08e64222a0c3111..f227ce74e7ec92d16a46ac546476c7e2f88312e5 100644 (file)
@@ -77,8 +77,6 @@ struct GPULamp {
        GPUTexture *depthtex;
        GPUTexture *blurtex;
 
-       ListBase materials;
-
        /* New viewport */
        struct LampEngineData data;
 };
index 40d1acfabd10871938184d6a72a5c7bc2bb64e8f..efe79c0386c7255eff4748b97d1f07304bbf7a3e 100644 (file)
@@ -250,21 +250,6 @@ void GPU_material_free(ListBase *gpumaterial)
                if (material->pass)
                        GPU_pass_free(material->pass);
 
-               for (LinkData *nlink = material->lamps.first; nlink; nlink = nlink->next) {
-                       GPULamp *lamp = nlink->data;
-
-                       if (material->ma) {
-                               Material *ma = material->ma;
-                               
-                               LinkData *next = NULL;
-                               for (LinkData *mlink = lamp->materials.first; mlink; mlink = next) {
-                                       next = mlink->next;
-                                       if (mlink->data == ma)
-                                               BLI_freelinkN(&lamp->materials, mlink);
-                               }
-                       }
-               }
-               
                BLI_freelistN(&material->lamps);
 
                MEM_freeN(material);
@@ -904,14 +889,12 @@ static void shade_one_light(GPUShadeInput *shi, GPUShadeResult *shr, GPULamp *la
                                }
                                
                                add_user_list(&mat->lamps, lamp);
-                               add_user_list(&lamp->materials, shi->gpumat->ma);
                                return;
                        }
                }
        }
        else if ((mat->scene->gm.flag & GAME_GLSL_NO_SHADOWS) && (lamp->mode & LA_ONLYSHADOW)) {
                add_user_list(&mat->lamps, lamp);
-               add_user_list(&lamp->materials, shi->gpumat->ma);
                return;
        }
        else
@@ -978,7 +961,6 @@ static void shade_one_light(GPUShadeInput *shi, GPUShadeResult *shr, GPULamp *la
        }
 
        add_user_list(&mat->lamps, lamp);
-       add_user_list(&lamp->materials, shi->gpumat->ma);
 }
 
 static void material_lights(GPUShadeInput *shi, GPUShadeResult *shr)
@@ -2289,7 +2271,6 @@ GPUNodeLink *GPU_lamp_get_data(
 
        /* ensure shadow buffer and lamp textures will be updated */
        add_user_list(&mat->lamps, lamp);
-       add_user_list(&lamp->materials, mat->ma);
 
        return visifac;
 }