Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BUG: Fix OpenGL errors/segfault when entering volume rendering module #552

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions Libs/MRML/Widgets/qMRMLSliceView.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
#include <vtkCollection.h>
#include <vtkNew.h>
#include <vtkObjectFactory.h>
#include <vtkRenderWindow.h>
#include <vtkSmartPointer.h>

//--------------------------------------------------------------------------
Expand Down Expand Up @@ -148,6 +149,14 @@ void qMRMLSliceViewPrivate::init()
this->LightBoxRendererManagerProxy->SetLightBoxRendererManager(
q->lightBoxRendererManager());
this->initDisplayableManagers();

// Force an initial render to ensure that the render window creates an OpenGL
// context. If operations that require a context--such as hardware
// picking--are performed when no context exists, OpenGL errors will occur.
// When using the VTK OpenGL2 backend the errors may be followed by a
// segfault. Such a scenario can occur when the app is started using a layout
// that hides one or more of the slice views.
q->renderWindow()->Render();
}

//---------------------------------------------------------------------------
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
if(Slicer_USE_QtTesting AND Slicer_USE_PYTHONQT)

# add a self test
# add tests
slicer_add_python_unittest(SCRIPT VolumeRenderingSceneClose.py)
slicer_add_python_unittest(SCRIPT VolumeRenderingThreeDOnlyLayout.py)
set_tests_properties(
py_VolumeRenderingThreeDOnlyLayout
PROPERTIES FAIL_REGULAR_EXPRESSION "OpenGL errors detected"
)
set(KIT_PYTHON_SCRIPTS
VolumeRenderingSceneClose.py
)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import unittest
import slicer


class VolumeRenderingThreeDOnlyLayout(unittest.TestCase):
def setUp(self):
pass

def tearDown(self):
slicer.mrmlScene.Clear(0)

def test_VolumeRenderThreeDOnlyLayout(self):
"""
Test that the following workflow does not segfault:
- Set 3D-only layout, reinitialize slice widgets
- Load volume
- Enter the volume rendering module
"""
# Set 3D-only layout
layoutManager = slicer.app.layoutManager()
layoutManager.setLayout(slicer.vtkMRMLLayoutNode.SlicerLayoutOneUp3DView)

# Reinitialize MRML scene to force re-creating slice widgets
mrmlScene = layoutManager.mrmlScene()
layoutManager.setMRMLScene(None)
layoutManager.setMRMLScene(mrmlScene)

# Load MRHead volume
from SampleData import SampleDataLogic
SampleDataLogic().downloadMRHead()

# Enter the volume rendering module
slicer.util.mainWindow().moduleSelector().selectModule('VolumeRendering')