fix for some errors reported by http://clang.blenderheads.org/trunk/ in r50384.
authorCampbell Barton <ideasman42@gmail.com>
Tue, 4 Sep 2012 18:27:47 +0000 (18:27 +0000)
committerCampbell Barton <ideasman42@gmail.com>
Tue, 4 Sep 2012 18:27:47 +0000 (18:27 +0000)
- when renderlayers could not be found in save_render_result_tile() blender would crash.
- RE_engine_end_result() / rna end_result() didn't set result argument as required.
... also some style cleanup.

source/blender/blenkernel/intern/image.c
source/blender/makesrna/intern/rna_render.c
source/blender/render/intern/source/external_engine.c
source/blender/render/intern/source/pipeline.c
source/blender/render/intern/source/render_result.c

index e652ea595d1ce9bb7c085320c9e99f056d2f0bab..ac307e036bf6654a0b2375a87a848b6c35b6df00 100644 (file)
@@ -2526,7 +2526,9 @@ static ImBuf *image_get_render_result(Image *ima, ImageUser *iuser, void **lock_
        dither = iuser->scene->r.dither_intensity;
 
        /* combined layer gets added as first layer */
-       if (rres.have_combined && layer == 0) ;
+       if (rres.have_combined && layer == 0) {
+               /* pass */
+       }
        else if (rres.layers.first) {
                RenderLayer *rl = BLI_findlink(&rres.layers, layer - (rres.have_combined ? 1 : 0));
                if (rl) {
index a755e130bb79d6ddebe0345a8ae8987170eedd71..d2e4e8edbfbaab50480429f213b2e18d9f77dadb 100644 (file)
@@ -317,7 +317,7 @@ static void rna_def_render_engine(BlenderRNA *brna)
        RNA_def_property_flag(prop, PROP_REQUIRED);
        prop = RNA_def_int(func, "h", 0, 0, INT_MAX, "Height", "", 0, INT_MAX);
        RNA_def_property_flag(prop, PROP_REQUIRED);
-       prop = RNA_def_string(func, "layer", "", 0, "Layer", "Single layer to get render result for");
+       RNA_def_string(func, "layer", "", 0, "Layer", "Single layer to get render result for");  /* NULL ok here */
        prop = RNA_def_pointer(func, "result", "RenderResult", "Result", "");
        RNA_def_function_return(func, prop);
 
@@ -327,6 +327,7 @@ static void rna_def_render_engine(BlenderRNA *brna)
 
        func = RNA_def_function(srna, "end_result", "RE_engine_end_result");
        prop = RNA_def_pointer(func, "result", "RenderResult", "Result", "");
+       RNA_def_property_flag(prop, PROP_REQUIRED);
        prop = RNA_def_boolean(func, "cancel", 0, "Cancel", "Don't merge back results");
        RNA_def_property_flag(prop, PROP_REQUIRED);
 
index 57993874c7a5d08088044eb485c8915353d43950..636b3205b23befa3cba0363ba3c887a882adae37 100644 (file)
@@ -205,17 +205,19 @@ void RE_engine_end_result(RenderEngine *engine, RenderResult *result, int cancel
        Render *re = engine->re;
        RenderPart *pa;
 
-       if (!result)
+       if (!result) {
                return;
+       }
 
        /* merge. on break, don't merge in result for preview renders, looks nicer */
        if (!cancel) {
                /* for exr tile render, detect tiles that are done */
                for (pa = re->parts.first; pa; pa = pa->next) {
                        if (result->tilerect.xmin == pa->disprect.xmin &&
-                          result->tilerect.ymin == pa->disprect.ymin &&
-                          result->tilerect.xmax == pa->disprect.xmax &&
-                          result->tilerect.ymax == pa->disprect.ymax) {
+                           result->tilerect.ymin == pa->disprect.ymin &&
+                           result->tilerect.xmax == pa->disprect.xmax &&
+                           result->tilerect.ymax == pa->disprect.ymax)
+                       {
                                pa->ready = 1;
                        }
                }
index 3e34b9d86d3c5ec91b5638b7f19a33b2f4452e00..44bd2c6d50f584fae54969922aaf769a3a25e7f6 100644 (file)
@@ -194,14 +194,12 @@ float *RE_RenderLayerGetPass(RenderLayer *rl, int passtype)
 
 RenderLayer *RE_GetRenderLayer(RenderResult *rr, const char *name)
 {
-       RenderLayer *rl;
-       
-       if (rr == NULL) return NULL;
-       
-       for (rl = rr->layers.first; rl; rl = rl->next)
-               if (strncmp(rl->name, name, RE_MAXNAME) == 0)
-                       return rl;
-       return NULL;
+       if (rr == NULL) {
+               return NULL;
+       }
+       else {
+               return BLI_findstring(&rr->layers, name, offsetof(RenderLayer, name));
+       }
 }
 
 RenderResult *RE_MultilayerConvert(void *exrhandle, int rectx, int recty)
@@ -1108,7 +1106,10 @@ static void merge_renderresult_fields(RenderResult *rr, RenderResult *rr1, Rende
                /* passes are allocated in sync */
                rpass1 = rl1->passes.first;
                rpass2 = rl2->passes.first;
-               for (rpass = rl->passes.first; rpass && rpass1 && rpass2; rpass = rpass->next, rpass1 = rpass1->next, rpass2 = rpass2->next) {
+               for (rpass = rl->passes.first;
+                    rpass && rpass1 && rpass2;
+                    rpass = rpass->next, rpass1 = rpass1->next, rpass2 = rpass2->next)
+               {
                        interleave_rect(rr, rpass->rect, rpass1->rect, rpass2->rect, rpass->channels);
                }
        }
index 4b0e46c9054c572f4c760e77c810039707a6bcde..2f932b2149e12a7af116aa8c1e9cb30de17cfae9 100644 (file)
@@ -30,6 +30,7 @@
  */
 
 #include <stdio.h>
+#include <stdlib.h>
 #include <string.h>
 
 #include "MEM_guardedalloc.h"
@@ -554,8 +555,9 @@ RenderResult *render_result_new(Render *re, rcti *partrct, int crop, int savebuf
                        IMB_exr_add_channel(rl->exrhandle, rl->name, "Combined.B", 0, 0, NULL);
                        IMB_exr_add_channel(rl->exrhandle, rl->name, "Combined.A", 0, 0, NULL);
                }
-               else
+               else {
                        rl->rectf = MEM_mapallocN(rectx * recty * sizeof(float) * 4, "Combined rgba");
+               }
                
                /* note, this has to be in sync with scene.c */
                rl->lay = (1 << 20) - 1;
@@ -691,16 +693,18 @@ void render_result_merge(RenderResult *rr, RenderResult *rrpart)
        RenderPass *rpass, *rpassp;
        
        for (rl = rr->layers.first; rl; rl = rl->next) {
-               for (rlp = rrpart->layers.first; rlp; rlp = rlp->next) {
-                       if (strcmp(rlp->name, rl->name) == 0) {
-                               /* combined */
-                               if (rl->rectf && rlp->rectf)
-                                       do_merge_tile(rr, rrpart, rl->rectf, rlp->rectf, 4);
-                               
-                               /* passes are allocated in sync */
-                               for (rpass = rl->passes.first, rpassp = rlp->passes.first; rpass && rpassp; rpass = rpass->next, rpassp = rpassp->next) {
-                                       do_merge_tile(rr, rrpart, rpass->rect, rpassp->rect, rpass->channels);
-                               }
+               rlp = RE_GetRenderLayer(rrpart, rl->name);
+               if (rlp) {
+                       /* combined */
+                       if (rl->rectf && rlp->rectf)
+                               do_merge_tile(rr, rrpart, rl->rectf, rlp->rectf, 4);
+
+                       /* passes are allocated in sync */
+                       for (rpass = rl->passes.first, rpassp = rlp->passes.first;
+                            rpass && rpassp;
+                            rpass = rpass->next, rpassp = rpassp->next)
+                       {
+                               do_merge_tile(rr, rrpart, rpass->rect, rpassp->rect, rpass->channels);
                        }
                }
        }
@@ -746,21 +750,24 @@ int RE_WriteRenderResult(ReportList *reports, RenderResult *rr, const char *file
                /* combined */
                if (rl->rectf) {
                        int a, xstride = 4;
-                       for (a = 0; a < xstride; a++)
-                               IMB_exr_add_channel(exrhandle, rl->name, get_pass_name(SCE_PASS_COMBINED, a), 
+                       for (a = 0; a < xstride; a++) {
+                               IMB_exr_add_channel(exrhandle, rl->name, get_pass_name(SCE_PASS_COMBINED, a),
                                                    xstride, xstride * rr->rectx, rl->rectf + a);
+                       }
                }
                
                /* passes are allocated in sync */
                for (rpass = rl->passes.first; rpass; rpass = rpass->next) {
                        int a, xstride = rpass->channels;
                        for (a = 0; a < xstride; a++) {
-                               if (rpass->passtype)
-                                       IMB_exr_add_channel(exrhandle, rl->name, get_pass_name(rpass->passtype, a), 
+                               if (rpass->passtype) {
+                                       IMB_exr_add_channel(exrhandle, rl->name, get_pass_name(rpass->passtype, a),
                                                            xstride, xstride * rr->rectx, rpass->rect + a);
-                               else
-                                       IMB_exr_add_channel(exrhandle, rl->name, make_pass_name(rpass, a), 
+                               }
+                               else {
+                                       IMB_exr_add_channel(exrhandle, rl->name, make_pass_name(rpass, a),
                                                            xstride, xstride * rr->rectx, rpass->rect + a);
+                               }
                        }
                }
        }
@@ -818,8 +825,9 @@ void render_result_single_layer_end(Render *re)
                
                /* reconstruct render result layers */
                for (nr = 0, srl = re->scene->r.layers.first; srl; srl = srl->next, nr++) {
-                       if (nr == re->r.actlay)
+                       if (nr == re->r.actlay) {
                                BLI_addtail(&re->result->layers, rl);
+                       }
                        else {
                                rlpush = RE_GetRenderLayer(re->pushedresult, srl->name);
                                if (rlpush) {
@@ -845,10 +853,14 @@ static void save_render_result_tile(RenderResult *rr, RenderResult *rrpart)
        BLI_lock_thread(LOCK_IMAGE);
        
        for (rlp = rrpart->layers.first; rlp; rlp = rlp->next) {
-               for (rl = rr->layers.first; rl; rl = rl->next)
-                       if (strcmp(rl->name, rlp->name) == 0)
-                               break;
-               
+               rl = RE_GetRenderLayer(rr, rlp->name);
+
+               /* should never happen but prevents crash if it does */
+               BLI_assert(rl);
+               if (UNLIKELY(rl == NULL)) {
+                       continue;
+               }
+
                if (rrpart->crop) { /* filters add pixel extra */
                        offs = (rrpart->crop + rrpart->crop * rrpart->rectx);
                }
@@ -859,17 +871,19 @@ static void save_render_result_tile(RenderResult *rr, RenderResult *rrpart)
                /* combined */
                if (rlp->rectf) {
                        int a, xstride = 4;
-                       for (a = 0; a < xstride; a++)
+                       for (a = 0; a < xstride; a++) {
                                IMB_exr_set_channel(rl->exrhandle, rlp->name, get_pass_name(SCE_PASS_COMBINED, a), 
                                                    xstride, xstride * rrpart->rectx, rlp->rectf + a + xstride * offs);
+                       }
                }
                
                /* passes are allocated in sync */
                for (rpassp = rlp->passes.first; rpassp; rpassp = rpassp->next) {
                        int a, xstride = rpassp->channels;
-                       for (a = 0; a < xstride; a++)
+                       for (a = 0; a < xstride; a++) {
                                IMB_exr_set_channel(rl->exrhandle, rlp->name, get_pass_name(rpassp->passtype, a), 
                                                    xstride, xstride * rrpart->rectx, rpassp->rect + a + xstride * offs);
+                       }
                }
                
        }
@@ -878,10 +892,14 @@ static void save_render_result_tile(RenderResult *rr, RenderResult *rrpart)
        partx = rrpart->tilerect.xmin + rrpart->crop;
 
        for (rlp = rrpart->layers.first; rlp; rlp = rlp->next) {
-               for (rl = rr->layers.first; rl; rl = rl->next)
-                       if (strcmp(rl->name, rlp->name) == 0)
-                               break;
-       
+               rl = RE_GetRenderLayer(rr, rlp->name);
+
+               /* should never happen but prevents crash if it does */
+               BLI_assert(rl);
+               if (UNLIKELY(rl == NULL)) {
+                       continue;
+               }
+
                IMB_exrtile_write_channels(rl->exrhandle, partx, party, 0);
        }