Fix crash on Scicos exiting when simulation was stoped and some scope closed
Jean-Baptiste Silvy [Fri, 20 Feb 2009 09:21:54 +0000 (10:21 +0100)]
scilab/modules/scicos_blocks/src/c/canimxy.c
scilab/modules/scicos_blocks/src/c/canimxy3d.c
scilab/modules/scicos_blocks/src/c/cevscpe.c
scilab/modules/scicos_blocks/src/c/cfscope.c
scilab/modules/scicos_blocks/src/c/cmat3d.c
scilab/modules/scicos_blocks/src/c/cmatview.c
scilab/modules/scicos_blocks/src/c/cmscope.c
scilab/modules/scicos_blocks/src/c/cscope.c
scilab/modules/scicos_blocks/src/c/cscopxy.c
scilab/modules/scicos_blocks/src/c/cscopxy3d.c
scilab/modules/scicos_blocks/src/c/graphics_Import.def

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
  
index 351adb5..4566c7f 100644 (file)
@@ -239,36 +239,40 @@ void canimxy3d(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);
-                     }
-                 }
-             }
+                               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);
+                                                       }
+                                               }
 
-           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
+                                               /* pShortDraw = sciGetCurrentFigure(); */
+                                               /*pShortDraw = scoGetPointerScopeWindow(pScopeMemory);*/
+                                               /*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
  
index f6a56ed..2f62390 100755 (executable)
@@ -177,29 +177,33 @@ void cevscpe(scicos_block * block, int flag)
     case Ending:
       {
 
-       scoRetrieveScopeMemory(block->work, &pScopeMemory);
-       if(scoGetScopeActivation(pScopeMemory) == 1)
-         {
-           sciSetUsedWindow(scoGetWindowID(pScopeMemory));
-           if(scoGetPointerScopeWindow(pScopeMemory) != NULL)
-             {
-               for(i = 0 ; i < scoGetNumberOfCurvesBySubwin(pScopeMemory,0) ; i++)
-                 {
-                   //maybe a bug here in the last argument of the following instruction (see tab[i])
-                   pLongDraw = scoGetPointerLongDraw(pScopeMemory,0,i);
-                   forceRedraw(pLongDraw);
-                 }
-             }
-
-           pShortDraw = sciGetCurrentFigure();
-           pFIGURE_FEATURE(pShortDraw)->user_data = NULL;
-           pFIGURE_FEATURE(pShortDraw)->size_of_user_data = 0;
-                       /* restore double buffering */
-                       sciSetJavaUseSingleBuffer(pShortDraw, FALSE);
-           scoDelCoupleOfSegments(pScopeMemory);
-         }
-       scoFreeScopeMemory(block->work,&pScopeMemory);
-       break;
-      }
-    }
+                               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. */
+                                       if(scoGetPointerScopeWindow(pScopeMemory) != NULL)
+                                       {
+                                               for(i = 0 ; i < scoGetNumberOfCurvesBySubwin(pScopeMemory,0) ; i++)
+                                               {
+                                                       /* maybe a bug here in the last argument of the following instruction (see tab[i]) */
+                                                       pLongDraw = scoGetPointerLongDraw(pScopeMemory,0,i);
+                                                       forceRedraw(pLongDraw);
+                                               }
+                                       
+
+                                               /* pShortDraw = sciGetCurrentFigure(); */
+                                               pShortDraw = scoGetPointerScopeWindow(pScopeMemory);
+                                               clearUserData(pShortDraw);
+                                               /* pFIGURE_FEATURE(pShortDraw)->user_data = NULL; */
+                                               /* pFIGURE_FEATURE(pShortDraw)->size_of_user_data = 0; */
+                                               /* restore double buffering */
+                                               sciSetJavaUseSingleBuffer(pShortDraw, FALSE);
+                                               scoDelCoupleOfSegments(pScopeMemory);
+                                       }
+                               }
+                               scoFreeScopeMemory(block->work,&pScopeMemory);
+                               break;
+                       }
+       }
 }
index 373b42f..1a130b6 100755 (executable)
@@ -189,12 +189,22 @@ void cfscope(scicos_block * block,int flag)
        scoRetrieveScopeMemory(block->work, &pScopeMemory);
        if(scoGetScopeActivation(pScopeMemory) == 1)
          {
-           sciSetUsedWindow(scoGetWindowID(pScopeMemory));
+           /*sciSetUsedWindow(scoGetWindowID(pScopeMemory));
            pShortDraw = sciGetCurrentFigure();
            pFIGURE_FEATURE(pShortDraw)->user_data = NULL;
            pFIGURE_FEATURE(pShortDraw)->size_of_user_data = 0;
            
-           scoDelCoupleOfPolylines(pScopeMemory);
+           scoDelCoupleOfPolylines(pScopeMemory);*/
+
+                       /* Check if figure is still opened, otherwise, don't try to destroy it again. */
+                       scoGraphicalObject figure = scoGetPointerScopeWindow(pScopeMemory);
+                       if (figure != NULL)
+                       {
+                               /*pShortDraw = scoGetPointerScopeWindow(pScopeMemory);*/
+                               clearUserData(figure);
+
+                               scoDelCoupleOfPolylines(pScopeMemory);
+                       }
          }
        scoFreeScopeMemory(block->work, &pScopeMemory);
        break;  
index 38a5246..c74ef22 100644 (file)
@@ -220,10 +220,17 @@ void cmat3d(scicos_block * block, int flag)
         /*Free Memory*/
        if(scoGetScopeActivation(pScopeMemory) == 1)
          {
-           sciSetUsedWindow(scoGetWindowID(pScopeMemory));
+           /*sciSetUsedWindow(scoGetWindowID(pScopeMemory));
            pShortDraw = sciGetCurrentFigure();
            pFIGURE_FEATURE(pShortDraw)->user_data = NULL;
-           pFIGURE_FEATURE(pShortDraw)->size_of_user_data = 0;
+           pFIGURE_FEATURE(pShortDraw)->size_of_user_data = 0;*/
+                       /* Check if figure is still opened, otherwise, don't try to destroy it again. */
+                       scoGraphicalObject figure = scoGetPointerScopeWindow(pScopeMemory);
+                       if (figure != NULL)
+                       {
+                               /*pShortDraw = scoGetPointerScopeWindow(pScopeMemory);*/
+                               clearUserData(figure);
+                       }
          }
        scoFreeScopeMemory(block->work, &pScopeMemory);
        break;
index 9480329..156c7cb 100644 (file)
@@ -161,16 +161,23 @@ void cmatview(scicos_block * block, int flag)
       }//End of stateupdate
     case Ending:
       {
-       scoRetrieveScopeMemory(block->work, &pScopeMemory);
-       if(scoGetScopeActivation(pScopeMemory) == 1)
-         {
-           sciSetUsedWindow(scoGetWindowID(pScopeMemory));
-           pShortDraw = sciGetCurrentFigure();
-           pFIGURE_FEATURE(pShortDraw)->user_data = NULL;
-           pFIGURE_FEATURE(pShortDraw)->size_of_user_data = 0;
-         }
-       scoFreeScopeMemory(block->work, &pScopeMemory);
-       break;
+                               scoRetrieveScopeMemory(block->work, &pScopeMemory);
+                               if(scoGetScopeActivation(pScopeMemory) == 1)
+                               {
+                                       /* sciSetUsedWindow(scoGetWindowID(pScopeMemory)); */
+                                       /*pShortDraw = sciGetCurrentFigure(); */
+                                       /*pFIGURE_FEATURE(pShortDraw)->user_data = NULL; */
+                                       /*pFIGURE_FEATURE(pShortDraw)->size_of_user_data = 0; */
+                                       /* Check if figure is still opened, otherwise, don't try to destroy it again. */
+                                       scoGraphicalObject figure = scoGetPointerScopeWindow(pScopeMemory);
+                                       if (figure != NULL)
+                                       {
+                                               /*pShortDraw = scoGetPointerScopeWindow(pScopeMemory);*/
+                                               clearUserData(figure);
+                                       }
+                               }
+                               scoFreeScopeMemory(block->work, &pScopeMemory);
+                               break;
       }
     }
 }
index b384a58..0cabc1f 100644 (file)
@@ -228,13 +228,25 @@ void cmscope(scicos_block * block, int flag)
        scoRetrieveScopeMemory(block->work, &pScopeMemory);
        if(scoGetScopeActivation(pScopeMemory) == 1)
          {
-           sciSetUsedWindow(scoGetWindowID(pScopeMemory));
-           pShortDraw = sciGetCurrentFigure();
-           pFIGURE_FEATURE(pShortDraw)->user_data = NULL;
-           pFIGURE_FEATURE(pShortDraw)->size_of_user_data = 0;
-                       /* restore double buffering */
-                       sciSetJavaUseSingleBuffer(pShortDraw, FALSE);
-           scoDelCoupleOfPolylines(pScopeMemory);
+         //  sciSetUsedWindow(scoGetWindowID(pScopeMemory));
+         //  pShortDraw = sciGetCurrentFigure();
+         //  pFIGURE_FEATURE(pShortDraw)->user_data = NULL;
+         //  pFIGURE_FEATURE(pShortDraw)->size_of_user_data = 0;
+                       ///* restore double buffering */
+                       //sciSetJavaUseSingleBuffer(pShortDraw, FALSE);
+         //  scoDelCoupleOfPolylines(pScopeMemory);
+
+
+                       /* Check if figure is still opened, otherwise, don't try to destroy it again. */
+                       scoGraphicalObject figure = scoGetPointerScopeWindow(pScopeMemory);
+                       if (figure != NULL)
+                       {
+                               /*pShortDraw = scoGetPointerScopeWindow(pScopeMemory);*/
+                               clearUserData(figure);
+
+                               sciSetJavaUseSingleBuffer(figure, FALSE);
+                         scoDelCoupleOfPolylines(pScopeMemory);
+                       }
 
          }
 
index 1ebc487..0bc25f7 100644 (file)
@@ -186,13 +186,24 @@ void cscope(scicos_block * block,int flag)
        scoRetrieveScopeMemory(block->work, &pScopeMemory);
        if(scoGetScopeActivation(pScopeMemory) == 1)
          {
-           sciSetUsedWindow(scoGetWindowID(pScopeMemory));
-           pShortDraw = sciGetCurrentFigure();
-           pFIGURE_FEATURE(pShortDraw)->user_data = NULL;
-           pFIGURE_FEATURE(pShortDraw)->size_of_user_data = 0;
-                       /* restore double buffering */
-                       sciSetJavaUseSingleBuffer(pShortDraw, FALSE);
-           scoDelCoupleOfPolylines(pScopeMemory);
+         //  sciSetUsedWindow(scoGetWindowID(pScopeMemory));
+         //  pShortDraw = sciGetCurrentFigure();
+         //  pFIGURE_FEATURE(pShortDraw)->user_data = NULL;
+         //  pFIGURE_FEATURE(pShortDraw)->size_of_user_data = 0;
+                       ///* restore double buffering */
+                       //sciSetJavaUseSingleBuffer(pShortDraw, FALSE);
+         //  scoDelCoupleOfPolylines(pScopeMemory);
+
+                       /* Check if figure is still opened, otherwise, don't try to destroy it again. */
+                       scoGraphicalObject figure = scoGetPointerScopeWindow(pScopeMemory);
+                       if (figure != NULL)
+                       {
+                               clearUserData(figure);
+                               /* restore double buffering */
+                               sciSetJavaUseSingleBuffer(figure, FALSE);
+                               scoDelCoupleOfPolylines(pScopeMemory);
+                       }
+
          }
        scoFreeScopeMemory(block->work, &pScopeMemory);
        break;  
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
       }
index 1109938..33384cb 100755 (executable)
@@ -189,21 +189,25 @@ void cscopxy3d(scicos_block * block, int flag)
       {
        scoRetrieveScopeMemory(block->work, &pScopeMemory);
        if(scoGetScopeActivation(pScopeMemory) == 1)
-         {
-           sciSetUsedWindow(scoGetWindowID(pScopeMemory));
-           
-           if (scoGetPointerScopeWindow(pScopeMemory) != NULL)
-             {
-               for(i = 0 ; i < scoGetNumberOfCurvesBySubwin(pScopeMemory,0) ; i++)
-                 {
-                   Pinceau = scoGetPointerLongDraw(pScopeMemory,0,i);
-                   forceRedraw(Pinceau);
-                 }
-             }
-           Pinceau = sciGetCurrentFigure();
-           pFIGURE_FEATURE(Pinceau)->user_data = NULL;
-           pFIGURE_FEATURE(Pinceau)->size_of_user_data = 0;
-         }
+       {
+               /* sciSetUsedWindow(scoGetWindowID(pScopeMemory)); */
+               /* 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);
+                       }
+               
+                       /* Pinceau = sciGetCurrentFigure();*/
+                       /*Pinceau = scoGetPointerScopeWindow(pScopeMemory);*/
+                       /* pFIGURE_FEATURE(Pinceau)->user_data = NULL; */
+                       /* pFIGURE_FEATURE(Pinceau)->size_of_user_data = 0; */
+                       clearUserData(figure);
+               }
+       }
        scoFreeScopeMemory(block->work, &pScopeMemory);
        break; //Break of the switch
       }