Partial fix for T37604: Deadlock when stopping rendered viewport (Blender Internal)
[blender.git] / source / blender / editors / space_view3d / space_view3d.c
index 6c61c2af81636eb61152e3b5edc7cb6a0b0a2521..03b89972e559d52c39aaad429bd127728f4495b6 100644 (file)
@@ -44,7 +44,9 @@
 
 #include "BKE_context.h"
 #include "BKE_icons.h"
+#include "BKE_main.h"
 #include "BKE_object.h"
+#include "BKE_scene.h"
 #include "BKE_screen.h"
 
 #include "ED_render.h"
 #include "WM_types.h"
 
 #include "RE_engine.h"
+#include "RE_pipeline.h"
 
 #include "RNA_access.h"
 
 #include "UI_resources.h"
 
+#ifdef WITH_PYTHON
+#  include "BPY_extern.h"
+#endif
+
 #include "view3d_intern.h"  /* own include */
 
 /* ******************** manage regions ********************* */
@@ -258,6 +265,42 @@ void ED_view3d_check_mats_rv3d(struct RegionView3D *rv3d)
 }
 #endif
 
+static void view3d_stop_render_preview(wmWindowManager *wm, ARegion *ar)
+{
+       RegionView3D *rv3d = ar->regiondata;
+
+       if (rv3d->render_engine) {
+#ifdef WITH_PYTHON
+               BPy_BEGIN_ALLOW_THREADS;
+#endif
+
+               WM_jobs_kill_type(wm, ar, WM_JOB_TYPE_RENDER_PREVIEW);
+
+#ifdef WITH_PYTHON
+               BPy_END_ALLOW_THREADS;
+#endif
+
+               if (rv3d->render_engine->re)
+                       RE_Database_Free(rv3d->render_engine->re);
+               RE_engine_free(rv3d->render_engine);
+               rv3d->render_engine = NULL;
+       }
+}
+
+void ED_view3d_shade_update(Main *bmain, View3D *v3d, ScrArea *sa)
+{
+       wmWindowManager *wm = bmain->wm.first;
+
+       if (v3d->drawtype != OB_RENDER) {
+               ARegion *ar;
+
+               for (ar = sa->regionbase.first; ar; ar = ar->next) {
+                       if (ar->regiondata)
+                               view3d_stop_render_preview(wm, ar);
+               }
+       }
+}
+
 /* ******************** default callbacks for view3d space ***************** */
 
 static SpaceLink *view3d_new(const bContext *C)
@@ -484,14 +527,11 @@ static void view3d_main_area_init(wmWindowManager *wm, ARegion *ar)
        
 }
 
-static void view3d_main_area_exit(wmWindowManager *UNUSED(wm), ARegion *ar)
+static void view3d_main_area_exit(wmWindowManager *wm, ARegion *ar)
 {
        RegionView3D *rv3d = ar->regiondata;
 
-       if (rv3d->render_engine) {
-               RE_engine_free(rv3d->render_engine);
-               rv3d->render_engine = NULL;
-       }
+       view3d_stop_render_preview(wm, ar);
 
        if (rv3d->gpuoffscreen) {
                GPU_offscreen_free(rv3d->gpuoffscreen);
@@ -747,6 +787,7 @@ static void view3d_main_area_listener(bScreen *sc, ScrArea *sa, ARegion *ar, wmN
                                case ND_OB_VISIBLE:
                                case ND_LAYER:
                                case ND_RENDER_OPTIONS:
+                               case ND_MARKERS:
                                case ND_MODE:
                                        ED_region_tag_redraw(ar);
                                        break;
@@ -804,7 +845,9 @@ static void view3d_main_area_listener(bScreen *sc, ScrArea *sa, ARegion *ar, wmN
                                case ND_SHADING:
                                case ND_NODES:
                                        if ((v3d->drawtype == OB_MATERIAL) ||
-                                           (v3d->drawtype == OB_TEXTURE && scene->gm.matmode == GAME_MAT_GLSL))
+                                           (v3d->drawtype == OB_TEXTURE &&
+                                                (scene->gm.matmode == GAME_MAT_GLSL ||
+                                                 BKE_scene_use_new_shading_nodes(scene))))
                                        {
                                                ED_region_tag_redraw(ar);
                                        }
@@ -820,14 +863,6 @@ static void view3d_main_area_listener(bScreen *sc, ScrArea *sa, ARegion *ar, wmN
                                case ND_WORLD_DRAW:
                                        /* handled by space_view3d_listener() for v3d access */
                                        break;
-                               case ND_WORLD_STARS:
-                               {
-                                       RegionView3D *rv3d = ar->regiondata;
-                                       if (rv3d->persp == RV3D_CAMOB) {
-                                               ED_region_tag_redraw(ar);
-                                       }
-                                       break;
-                               }
                        }
                        break;
                case NC_LAMP: