0025133: TKOpenGl - Crash on closing a view containing presentations with capping
[occt.git] / src / OpenGl / OpenGl_AspectMarker.cxx
index 791ab86..ae2a74d 100644 (file)
@@ -4,8 +4,8 @@
 //
 // This file is part of Open CASCADE Technology software library.
 //
-// This library is free software; you can redistribute it and / or modify it
-// under the terms of the GNU Lesser General Public version 2.1 as published
+// This library is free software; you can redistribute it and/or modify it under
+// the terms of the GNU Lesser General Public License version 2.1 as published
 // by the Free Software Foundation, with special exception defined in the file
 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
 // distribution for complete text of the license and disclaimer of any warranty.
@@ -1462,13 +1462,13 @@ OpenGl_AspectMarker::OpenGl_AspectMarker()
 // =======================================================================
 void OpenGl_AspectMarker::SetAspect (const CALL_DEF_CONTEXTMARKER& theAspect)
 {
-  myColor.rgb[0] = (float )theAspect.Color.r;
-  myColor.rgb[1] = (float )theAspect.Color.g;
-  myColor.rgb[2] = (float )theAspect.Color.b;
-  myColor.rgb[3] = 1.0f;
-  myMarkerImage  = theAspect.MarkerImage;
-  myType         = theAspect.MarkerType;
-  myScale = myMarkerSize = theAspect.Scale;
+  myColor.rgb[0]  = (float )theAspect.Color.r;
+  myColor.rgb[1]  = (float )theAspect.Color.g;
+  myColor.rgb[2]  = (float )theAspect.Color.b;
+  myColor.rgb[3]  = 1.0f;
+  myMarkerImage   = theAspect.MarkerImage;
+  myType          = theAspect.MarkerType;
+  myScale         = theAspect.Scale;
   myShaderProgram = theAspect.ShaderProgram;
 
   // update sprite resource bindings
@@ -1476,13 +1476,11 @@ void OpenGl_AspectMarker::SetAspect (const CALL_DEF_CONTEXTMARKER& theAspect)
   TCollection_AsciiString aSpriteAKey = THE_EMPTY_KEY;
   myResources.SpriteKeys (myMarkerImage, myType, myScale, myColor, aSpriteKey, aSpriteAKey);
 
-  if (aSpriteKey.IsEmpty() || myResources.SpriteKey != aSpriteKey)
-  {
-    myResources.ResetSpriteReadiness();
-  }
-  if (aSpriteAKey.IsEmpty() || myResources.SpriteAKey != aSpriteAKey)
+  if (aSpriteKey.IsEmpty()  || myResources.SpriteKey  != aSpriteKey
+   || aSpriteAKey.IsEmpty() || myResources.SpriteAKey != aSpriteAKey)
   {
     myResources.ResetSpriteReadiness();
+    myMarkerSize = theAspect.Scale;
   }
 
   // update shader program resource bindings
@@ -1507,11 +1505,11 @@ void OpenGl_AspectMarker::Render (const Handle(OpenGl_Workspace)& theWorkspace)
 // function : Release
 // purpose  :
 // =======================================================================
-void OpenGl_AspectMarker::Release (const Handle(OpenGl_Context)& theCtx)
+void OpenGl_AspectMarker::Release (OpenGl_Context* theCtx)
 {
   if (!myResources.Sprite.IsNull())
   {
-    if (!theCtx.IsNull())
+    if (theCtx)
     {
       if (myResources.SpriteKey.IsEmpty())
       {
@@ -1533,7 +1531,7 @@ void OpenGl_AspectMarker::Release (const Handle(OpenGl_Context)& theCtx)
   myResources.SpriteAKey.Clear();
   myResources.ResetSpriteReadiness();
 
-  if (!myResources.ShaderProgram.IsNull() && !theCtx.IsNull())
+  if (!myResources.ShaderProgram.IsNull() && theCtx)
   {
     theCtx->ShaderManager()->Unregister (myResources.ShaderProgramId,
                                          myResources.ShaderProgram);
@@ -1712,8 +1710,6 @@ void OpenGl_AspectMarker::Resources::BuildSprites (const Handle(OpenGl_Workspace
           anImageA = new Image_PixMap();
           anImage ->InitZero (Image_PixMap::ImgBGRA, aSize, aSize);
           anImageA->InitZero (Image_PixMap::ImgGray, aSize, aSize);
-          Image_PixMapData<Image_ColorBGRA>& aDataBGRA = anImage->EditData<Image_ColorBGRA>();
-          Image_PixMapData<Standard_Byte>&   aDataGray = anImageA->EditData<Standard_Byte>();
 
           // we draw a set of circles
           Image_ColorBGRA aColor32;
@@ -1731,8 +1727,8 @@ void OpenGl_AspectMarker::Resources::BuildSprites (const Handle(OpenGl_Workspace
             const Handle(Graphic3d_MarkerImage) aMarker = GetTextureImage (Aspect_TOM_O, aScale);
             const Handle(Image_PixMap)& aCircle = aMarker->GetImage();
 
-            const Standard_Size aDiffX = (aDataBGRA.SizeX() - aCircle->SizeX()) / 2;
-            const Standard_Size aDiffY = (aDataBGRA.SizeY() - aCircle->SizeY()) / 2;
+            const Standard_Size aDiffX = (anImage->SizeX() - aCircle->SizeX()) / 2;
+            const Standard_Size aDiffY = (anImage->SizeY() - aCircle->SizeY()) / 2;
             for (Standard_Size aRow = 0; aRow < aCircle->SizeY(); ++aRow)
             {
               const Standard_Byte* aRowData = aCircle->Row (aRow);
@@ -1740,8 +1736,8 @@ void OpenGl_AspectMarker::Resources::BuildSprites (const Handle(OpenGl_Workspace
               {
                 if (aRowData[aCol] != 0)
                 {
-                  aDataBGRA.ChangeValue (aDiffX + aRow, aDiffY + aCol) = aColor32;
-                  aDataGray.ChangeValue (aDiffX + aRow, aDiffY + aCol) = 255;
+                  anImage ->ChangeValue<Image_ColorBGRA> (aDiffX + aRow, aDiffY + aCol) = aColor32;
+                  anImageA->ChangeValue<Standard_Byte>   (aDiffX + aRow, aDiffY + aCol) = 255;
                 }
               }
             }