Fix crash on Scicos exiting when simulation was stoped and some scope closed
[scilab.git] / scilab / modules / scicos_blocks / src / c / cscopxy.c
index c3d8730..3af2f0a 100755 (executable)
@@ -170,23 +170,27 @@ void cscopxy(scicos_block * block, int flag)
        scoRetrieveScopeMemory(block->work, &pScopeMemory);
        if(scoGetScopeActivation(pScopeMemory) == 1)
          {
-           sciSetUsedWindow(scoGetWindowID(pScopeMemory));
+           /*sciSetUsedWindow(scoGetWindowID(pScopeMemory));*/
            
-           if (scoGetPointerScopeWindow(pScopeMemory) != NULL)
-             {
-               for(i = 0 ; i < scoGetNumberOfCurvesBySubwin(pScopeMemory,0); i++)
-                 {
-                   Pinceau = scoGetPointerLongDraw(pScopeMemory,0,i);
-                   forceRedraw(Pinceau);
-                 }
-             }
-            //Here Pinceau = Window
-           Pinceau = sciGetCurrentFigure();
-           pFIGURE_FEATURE(Pinceau)->user_data = NULL;
-           pFIGURE_FEATURE(Pinceau)->size_of_user_data = 0;
-                       /* restore double buffering */
-                       sciSetJavaUseSingleBuffer(Pinceau, FALSE);
-         }
+                       /* Check if figure is still opened, otherwise, don't try to destroy it again. */
+                       scoGraphicalObject figure = scoGetPointerScopeWindow(pScopeMemory);
+                       if (figure != NULL)
+                       {
+                               for(i = 0 ; i < scoGetNumberOfCurvesBySubwin(pScopeMemory,0); i++)
+                               {
+                                       Pinceau = scoGetPointerLongDraw(pScopeMemory,0,i);
+                                       forceRedraw(Pinceau);
+                               }
+                       
+                               //Here Pinceau = Window
+                               /*Pinceau = sciGetCurrentFigure();*/
+                               /*pFIGURE_FEATURE(Pinceau)->user_data = NULL;
+                               pFIGURE_FEATURE(Pinceau)->size_of_user_data = 0;*/
+                               clearUserData(figure);
+                               /* restore double buffering */
+                               sciSetJavaUseSingleBuffer(figure, FALSE);
+                       }
+       }
        scoFreeScopeMemory(block->work, &pScopeMemory);
        break; //Break of the switch
       }