0030469: Visualization - Draw crashes when 3D view is minimized
authorkgv <kgv@opencascade.com>
Fri, 1 Feb 2019 13:20:24 +0000 (16:20 +0300)
committerbugmaster <bugmaster@opencascade.com>
Mon, 4 Feb 2019 13:26:23 +0000 (16:26 +0300)
OpenGl_View::Redraw() - avoid rendering into window of zero size (leading to FPE and other issues).

src/OpenGl/OpenGl_BVHTreeSelector.cxx
src/OpenGl/OpenGl_View_Redraw.cxx

index a3bcd1e..95edcad 100644 (file)
@@ -96,10 +96,10 @@ void OpenGl_BVHTreeSelector::SetViewportSize (Standard_Integer theViewportWidth,
                                               Standard_Integer theViewportHeight,
                                               Standard_Real theResolutionRatio)
 {
-  myViewportHeight = theViewportHeight;
-  myViewportWidth  = theViewportWidth;
-  myPixelSize = Max (theResolutionRatio / theViewportHeight,
-                     theResolutionRatio / theViewportWidth);
+  myViewportHeight = theViewportHeight > 0 ? theViewportHeight : 1;
+  myViewportWidth  = theViewportWidth  > 0 ? theViewportWidth  : 1;
+  myPixelSize = Max (theResolutionRatio / myViewportHeight,
+                     theResolutionRatio / myViewportWidth);
 }
 
 // =======================================================================
index b88fcd1..2a6c5d1 100644 (file)
@@ -179,10 +179,19 @@ void OpenGl_View::Redraw()
             && !aCtx->caps->buffersNoSwap
             &&  aFrameBuffer == NULL;
 
-  Standard_Integer aSizeX = aFrameBuffer != NULL ? aFrameBuffer->GetVPSizeX() : myWindow->Width();
-  Standard_Integer aSizeY = aFrameBuffer != NULL ? aFrameBuffer->GetVPSizeY() : myWindow->Height();
-  Standard_Integer aRendSizeX = Standard_Integer(myRenderParams.RenderResolutionScale * aSizeX + 0.5f);
-  Standard_Integer aRendSizeY = Standard_Integer(myRenderParams.RenderResolutionScale * aSizeY + 0.5f);
+  const Standard_Integer aSizeX = aFrameBuffer != NULL ? aFrameBuffer->GetVPSizeX() : myWindow->Width();
+  const Standard_Integer aSizeY = aFrameBuffer != NULL ? aFrameBuffer->GetVPSizeY() : myWindow->Height();
+  const Standard_Integer aRendSizeX = Standard_Integer(myRenderParams.RenderResolutionScale * aSizeX + 0.5f);
+  const Standard_Integer aRendSizeY = Standard_Integer(myRenderParams.RenderResolutionScale * aSizeY + 0.5f);
+  if (aSizeX < 1
+   || aSizeY < 1
+   || aRendSizeX < 1
+   || aRendSizeY < 1)
+  {
+    myBackBufferRestored = Standard_False;
+    myIsImmediateDrawn   = Standard_False;
+    return;
+  }
 
   // determine multisampling parameters
   Standard_Integer aNbSamples = !myToDisableMSAA && aSizeX == aRendSizeX