@@ -363,6 +363,7 @@ void *render_thread_interactive(void *arg) {
363363 long total_us = 0 ;
364364
365365 timer_start (& timer );
366+ thread_rwlock_rdlock (r -> scene -> bvh_lock );
366367 for (int y = tile -> end .y - 1 ; y > tile -> begin .y - 1 ; -- y ) {
367368 for (int x = tile -> begin .x ; x < tile -> end .x ; ++ x ) {
368369 if (r -> state .s != r_rendering ) goto exit ;
@@ -373,9 +374,7 @@ void *render_thread_interactive(void *arg) {
373374 sampler_init (sampler , SAMPLING_STRATEGY , r -> state .finishedPasses , r -> prefs .sampleCount , pixIdx );
374375
375376 struct color output = tex_get_px (* buf , x , y , false);
376- thread_rwlock_rdlock (r -> scene -> bvh_lock );
377377 struct color sample = path_trace (cam_get_ray (cam , x , y , sampler ), r -> scene , r -> prefs .bounces , sampler );
378- thread_rwlock_unlock (r -> scene -> bvh_lock );
379378
380379 nan_clamp (& sample , & output );
381380
@@ -389,6 +388,7 @@ void *render_thread_interactive(void *arg) {
389388 tex_set_px (* buf , output , x , y );
390389 }
391390 }
391+ thread_rwlock_unlock (r -> scene -> bvh_lock );
392392 //For performance metrics
393393 total_us += timer_get_us (timer );
394394 threadState -> totalSamples ++ ;
0 commit comments