0029127: Visualization - V3d_View::ToPixMap() crashes on tiled rendering without FBO
authorkgv <kgv@opencascade.com>
Wed, 20 Sep 2017 11:28:26 +0000 (14:28 +0300)
committerbugmaster <bugmaster@opencascade.com>
Thu, 28 Sep 2017 07:41:44 +0000 (10:41 +0300)
Fixed out-of-memory writing within fallback View dump mode.

src/V3d/V3d_View.cxx
tests/bugs/vis/bug29127 [new file with mode: 0644]

index cd15176..aaf1b2d 100644 (file)
@@ -2945,16 +2945,11 @@ Standard_Boolean V3d_View::ToPixMap (Image_PixMap&               theImage,
       anOffset.x() = 0;
       for (; anOffset.x() < aTargetSize.x(); anOffset.x() += aFBOVPSize.x())
       {
-        Graphic3d_CameraTile aTile;
-        aTile.Offset    = anOffset;
-        aTile.TotalSize = aTargetSize;
-        aTile.TileSize  = aFBOVPSize;
-        if (!aFBOPtr.IsNull())
-        {
-          // crop corners in case of FBO
-          // (no API to resize viewport of on-screen buffer - keep uncropped in this case)
-          aTile = aTile.Cropped();
-        }
+        Graphic3d_CameraTile aTileUncropped;
+        aTileUncropped.Offset    = anOffset;
+        aTileUncropped.TotalSize = aTargetSize;
+        aTileUncropped.TileSize  = aFBOVPSize;
+        const Graphic3d_CameraTile aTile = aTileUncropped.Cropped();
         if (aTile.TileSize.x() < 1
          || aTile.TileSize.y() < 1)
         {
@@ -2973,11 +2968,16 @@ Standard_Boolean V3d_View::ToPixMap (Image_PixMap&               theImage,
                                  aTile.TileSize.x(), aTile.TileSize.y(),
                                  theImage.SizeRowBytes());
 
-        aCamera->SetTile (aTile);
         if (!aFBOPtr.IsNull())
         {
+          aCamera->SetTile (aTile);
           myView->FBOChangeViewport (aFBOPtr, aTile.TileSize.x(), aTile.TileSize.y());
         }
+        else
+        {
+          // no API to resize viewport of on-screen buffer - render uncropped
+          aCamera->SetTile (aTileUncropped);
+        }
         Redraw();
         isSuccess = isSuccess && myView->BufferDump (aTilePixMap, theParams.BufferType);
         if (!isSuccess)
diff --git a/tests/bugs/vis/bug29127 b/tests/bugs/vis/bug29127
new file mode 100644 (file)
index 0000000..5628b26
--- /dev/null
@@ -0,0 +1,18 @@
+puts "============"
+puts "0029127: Visualization - V3d_View::ToPixMap() crashes on tiled rendering without FBO"
+puts "============"
+puts ""
+
+pload MODELING VISUALIZATION
+box b 1 2 3 
+# request software OpenGL implementation - which is OpenGL 1.1 in case of Windows
+# (test case is useless for other systems)
+vcaps -softMode 1
+vclear
+vinit View1
+vsetdispmode 1
+vdisplay b
+vfit
+vdump $::imagedir/${::casename}_409.png -buffer rgb -width 409 -height 409
+vdump $::imagedir/${::casename}_412.png -buffer rgb -width 412 -height 412 -tileSize 409
+vdump $::imagedir/${::casename}_500.png -buffer rgb -width 500 -height 500 -tileSize 300