Fix crash on Scicos exiting when simulation was stoped and some scope closed
[scilab.git] / scilab / modules / scicos_blocks / src / c / canimxy.c
index 3422f5a..547f869 100755 (executable)
@@ -235,36 +235,39 @@ void canimxy(scicos_block * block, int flag)
       //This case is activated when the simulation is done or when we close scicos
     case Ending:
       {
-       scoRetrieveScopeMemory(block->work, &pScopeMemory);
-       if(scoGetScopeActivation(pScopeMemory) == 1)
-         {
-           sciSetUsedWindow(scoGetWindowID(pScopeMemory));
-           if (scoGetPointerScopeWindow(pScopeMemory) != NULL)
-             {
-               if(scoGetLongDrawSize(pScopeMemory,0) == 0)
-                 {
-                   for(i = 0 ; i < scoGetNumberOfCurvesBySubwin(pScopeMemory,0) ; i++)
-                     {
-                       pLongDraw = scoGetPointerLongDraw(pScopeMemory,0,i);
-                       forceRedraw(pLongDraw);
-                     }
-                 }
-               else
-                 {
-                   for(i = 0 ; i < scoGetNumberOfCurvesBySubwin(pScopeMemory,0)/2 ; i++)
-                     {
-                       pLongDraw = scoGetPointerLongDraw(pScopeMemory,0,i);
-                       forceRedraw(pLongDraw);
-                     }
-                 }
-             }
-           //Attention : here pShortDraw is a Window
-           pShortDraw = sciGetCurrentFigure();
-           pFIGURE_FEATURE(pShortDraw)->user_data = NULL;
-           pFIGURE_FEATURE(pShortDraw)->size_of_user_data = 0;
-         }
-       scoFreeScopeMemory(block->work, &pScopeMemory);
-       break; //Break of the switch
+                               scoRetrieveScopeMemory(block->work, &pScopeMemory);
+                               if(scoGetScopeActivation(pScopeMemory) == 1)
+                               {
+                                       /* sciSetUsedWindow(scoGetWindowID(pScopeMemory)); */
+                                       /* Check if figure is still opened, otherwise, don't try to destroy it again. */
+                                       scoGraphicalObject figure = scoGetPointerScopeWindow(pScopeMemory);
+                                       if (figure != NULL)
+                                       {
+                                               if(scoGetLongDrawSize(pScopeMemory,0) == 0)
+                                               {
+                                                       for(i = 0 ; i < scoGetNumberOfCurvesBySubwin(pScopeMemory,0) ; i++)
+                                                       {
+                                                               pLongDraw = scoGetPointerLongDraw(pScopeMemory,0,i);
+                                                               forceRedraw(pLongDraw);
+                                                       }
+                                               }
+                                               else
+                                               {
+                                                       for(i = 0 ; i < scoGetNumberOfCurvesBySubwin(pScopeMemory,0)/2 ; i++)
+                                                       {
+                                                               pLongDraw = scoGetPointerLongDraw(pScopeMemory,0,i);
+                                                               forceRedraw(pLongDraw);
+                                                       }
+                                               }
+                                       }
+                                       //Attention : here pShortDraw is a Window
+                                       /* pShortDraw = sciGetCurrentFigure(); */
+                                       /*pFIGURE_FEATURE(pShortDraw)->user_data = NULL;*/
+                                       /*pFIGURE_FEATURE(pShortDraw)->size_of_user_data = 0;*/
+                                       clearUserData(figure);
+                               }
+                               scoFreeScopeMemory(block->work, &pScopeMemory);
+                               break; //Break of the switch
       }
       //free the memory which is allocated at each turn by some variables