Attempted fixes for render crashes on windows, still can't redo them here
authorBrecht Van Lommel <brechtvanlommel@pandora.be>
Thu, 1 Apr 2010 12:51:24 +0000 (12:51 +0000)
committerBrecht Van Lommel <brechtvanlommel@pandora.be>
Thu, 1 Apr 2010 12:51:24 +0000 (12:51 +0000)
in a virtual machine, maybe that has some different threading behavior.
Also should fix a problem with displaying render passes and multiple slots.

source/blender/blenkernel/intern/image.c
source/blender/editors/render/render_internal.c
source/blender/editors/space_image/image_draw.c
source/blender/render/extern/include/RE_pipeline.h
source/blender/render/intern/source/pipeline.c

index 2d5821572337036f8667e3ad38957958798803fc..63bfbc3d093f18c617530a42b71037e1baa04e49 100644 (file)
@@ -1894,13 +1894,16 @@ static ImBuf *image_get_render_result(Image *ima, ImageUser *iuser, void **lock_
                memset(&rres, 0, sizeof(RenderResult));
        
        if(!(rres.rectx > 0 && rres.recty > 0)) {
-               RE_ReleaseResultImage(re);
+               if(from_render)
+                       RE_ReleaseResultImage(re);
                return NULL;
        }
 
        /* release is done in BKE_image_release_ibuf using lock_r */
-       if(from_render)
+       if(from_render) {
+               BLI_lock_thread(LOCK_VIEWER);
                *lock_r= re;
+       }
 
        /* this gives active layer, composite or seqence result */
        rect= (unsigned int *)rres.rect32;
@@ -1909,9 +1912,9 @@ static ImBuf *image_get_render_result(Image *ima, ImageUser *iuser, void **lock_
        dither= iuser->scene->r.dither_intensity;
 
        /* get compo/seq result by default */
-       if(rres.rectf && layer==0);
+       if(rres.compo_seq && layer==0);
        else if(rres.layers.first) {
-               RenderLayer *rl= BLI_findlink(&rres.layers, layer-(rres.rectf?1:0));
+               RenderLayer *rl= BLI_findlink(&rres.layers, layer-(rres.compo_seq?1:0));
                if(rl) {
                        RenderPass *rpass;
 
@@ -1934,6 +1937,9 @@ static ImBuf *image_get_render_result(Image *ima, ImageUser *iuser, void **lock_
                }
        }
 
+       if(!(rectf || rect))
+               return NULL;
+
        ibuf= image_get_ibuf(ima, IMA_NO_INDEX, 0);
 
        /* make ibuf if needed, and initialize it */
@@ -1942,17 +1948,12 @@ static ImBuf *image_get_render_result(Image *ima, ImageUser *iuser, void **lock_
                image_assign_ibuf(ima, ibuf, IMA_NO_INDEX, 0);
        }
 
-       if(!(rectf || rect))
-               return ibuf;
-
        ibuf->x= rres.rectx;
        ibuf->y= rres.recty;
        
-       if(ibuf->rect_float!=rectf || rect) { /* ensure correct redraw */
-               BLI_lock_thread(LOCK_CUSTOM1);
+       if(ibuf->rect_float!=rectf || rect) /* ensure correct redraw */
                imb_freerectImBuf(ibuf);
-               BLI_unlock_thread(LOCK_CUSTOM1);
-       }
+
        if(rect)
                ibuf->rect= rect;
        
@@ -1991,7 +1992,7 @@ static ImBuf *image_get_ibuf_threadsafe(Image *ima, ImageUser *iuser, int *frame
                        if(ima->lastframe != frame)
                                ima->tpageflag |= IMA_TPAGE_REFRESH;
                        ima->lastframe = frame;
-               }
+               }       
                else if(ima->type==IMA_TYPE_MULTILAYER) {
                        frame= iuser?iuser->framenr:ima->lastframe;
                        index= iuser?iuser->multi_index:IMA_NO_INDEX;
@@ -2155,10 +2156,13 @@ ImBuf *BKE_image_acquire_ibuf(Image *ima, ImageUser *iuser, void **lock_r)
 void BKE_image_release_ibuf(Image *ima, void *lock)
 {
        /* for getting image during threaded render / compositing, need to release */
-       if(lock == ima)
+       if(lock == ima) {
                BLI_unlock_thread(LOCK_VIEWER); /* viewer image */
-       else if(lock)
+       }
+       else if(lock) {
                RE_ReleaseResultImage(lock); /* render result */
+               BLI_unlock_thread(LOCK_VIEWER); /* view image imbuf */
+       }
 }
 
 ImBuf *BKE_image_get_ibuf(Image *ima, ImageUser *iuser)
index dcafbc5b252b69aa1aa0592627ec4be536596ee0..3f98a340b747b42b06c2f824975fb3ca11a6c7ff 100644 (file)
@@ -129,12 +129,8 @@ void image_buffer_rect_update(Scene *scene, RenderResult *rr, ImBuf *ibuf, volat
        }
        if(rectf==NULL) return;
 
-       if(ibuf->rect==NULL) {
-               BLI_lock_thread(LOCK_CUSTOM1);
-               if(ibuf->rect==NULL)
-                       imb_addrectImBuf(ibuf);
-               BLI_unlock_thread(LOCK_CUSTOM1);
-       }
+       if(ibuf->rect==NULL)
+               imb_addrectImBuf(ibuf);
 
        rectf+= 4*(rr->rectx*ymin + xmin);
        rectc= (char *)(ibuf->rect + ibuf->x*rymin + rxmin);
@@ -505,17 +501,22 @@ static void image_renderinfo_cb(void *rjv, RenderStats *rs)
 static void image_rect_update(void *rjv, RenderResult *rr, volatile rcti *renrect)
 {
        RenderJob *rj= rjv;
+       Image *ima= rj->image;
        ImBuf *ibuf;
        void *lock;
 
-       ibuf= BKE_image_acquire_ibuf(rj->image, &rj->iuser, &lock);
+       /* only update if we are displaying the slot being rendered */
+       if(ima->render_slot != ima->last_render_slot)
+               return;
+
+       ibuf= BKE_image_acquire_ibuf(ima, &rj->iuser, &lock);
        if(ibuf) {
                image_buffer_rect_update(rj->scene, rr, ibuf, renrect);
 
                /* make jobs timer to send notifier */
                *(rj->do_update)= 1;
        }
-       BKE_image_release_ibuf(rj->image, lock);
+       BKE_image_release_ibuf(ima, lock);
 }
 
 static void render_startjob(void *rjv, short *stop, short *do_update)
index 55bec0740eaf854d4b9f227dd4a6a35ac2317c18..a611ee6f32f7e8d88501d569e4f2227d7ab80917 100644 (file)
@@ -77,18 +77,14 @@ static void image_verify_buffer_float(SpaceImage *sima, Image *ima, ImBuf *ibuf,
        */
 
        if(ibuf->rect_float && ibuf->rect==NULL) {
-               BLI_lock_thread(LOCK_CUSTOM1);
-               if(ibuf->rect_float && ibuf->rect==NULL) {
-                       if(color_manage) {
-                                       if(ima && ima->source == IMA_SRC_VIEWER)
-                                               ibuf->profile = IB_PROFILE_LINEAR_RGB;
-                       }
-                       else
-                               ibuf->profile = IB_PROFILE_NONE;
-
-                       IMB_rect_from_float(ibuf);
+               if(color_manage) {
+                       if(ima && ima->source == IMA_SRC_VIEWER)
+                               ibuf->profile = IB_PROFILE_LINEAR_RGB;
                }
-               BLI_unlock_thread(LOCK_CUSTOM1);
+               else
+                       ibuf->profile = IB_PROFILE_NONE;
+
+               IMB_rect_from_float(ibuf);
        }
 }
 
index c0d1d2513561f7505a2fafff0805240877d6ce06..0d8161c9a7a82825e10cf7ca4a14256c493c8b3d 100644 (file)
@@ -130,6 +130,9 @@ typedef struct RenderResult {
        /* for render results in Image, verify validity for sequences */
        int framenr;
 
+       /* for acquire image, to indicate if it is compo/seq result */
+       int compo_seq;
+
        /* render info text */
        char *text;
        
index 2d7b724d89319b0418c4e45b46aba2ba137011b4..f9089e7399b318b0e5d4b591cdabc1b2516c967a 100644 (file)
@@ -1061,6 +1061,7 @@ void RE_AcquireResultImage(Render *re, RenderResult *rr)
                        rr->rectf= re->result->rectf;
                        rr->rectz= re->result->rectz;
                        rr->rect32= re->result->rect32;
+                       rr->compo_seq= (rr->rectf != NULL);
                        
                        /* active layer */
                        rl= render_get_active_layer(re, re->result);