View Issue Details

IDProjectCategoryView StatusLast Update
0003438Slicer4Core: GUIpublic2017-06-07 23:27
Reporterlassoan Assigned Tojcfr  
PrioritynormalSeveritymajorReproducibilityrandom
Status closedResolutionfixed 
Product Version 
Target VersionSlicer 4.4.0Fixed in VersionSlicer 4.4.0 
Summary0003438: Slicer somettimes hangs at the end of scene saving
Description

Seems to be an issue with OpenGL error handling in VTK in vtkOpenGLRenderWindow::GetPixelData().

int vtkOpenGLRenderWindow::GetPixelData(int x1, int y1,
int x2, int y2,
int front, unsigned char* data)
{
int y_low, y_hi;
int x_low, x_hi;

// set the current window
this->MakeCurrent();
...
// Must clear previous errors first.
while(glGetError() != GL_NO_ERROR)
{
;
}

...

Additional Information

Stack traces:

OPENGL32.dll!glDebugEntry+0x10
vtkRendering.dll!vtkOpenGLRenderWindow::GetPixelData+0x56
vtkRendering.dll!vtkOpenGLRenderWindow::GetPixelData+0xcb
QVTK.dll!QVTKWidget::saveImageToCache+0xdc
QVTK.dll!QVTKWidget::cachedImage+0x1c
CTKVisualizationVTKWidgets.dll!ctk::grabVTKWidget+0x367
qSlicerBaseQTGUI.dll!qSlicerSaveDataDialog::~qSlicerSaveDataDialog+0x4b38
qSlicerBaseQTGUI.dll!qSlicerSaveDataDialog::~qSlicerSaveDataDialog+0x53e2

OPENGL32.dll!glGetError
vtkRendering.dll!vtkOpenGLRenderWindow::GetPixelData+0x56
vtkRendering.dll!vtkOpenGLRenderWindow::GetPixelData+0xcb
QVTK.dll!QVTKWidget::saveImageToCache+0xdc
QVTK.dll!QVTKWidget::cachedImage+0x1c
CTKVisualizationVTKWidgets.dll!ctk::grabVTKWidget+0x367
qSlicerBaseQTGUI.dll!qSlicerSaveDataDialog::~qSlicerSaveDataDialog+0x4b38
qSlicerBaseQTGUI.dll!qSlicerSaveDataDialog::~qSlicerSaveDataDialog+0x53e2
qSlicerBaseQTGUI.dll!qSlicerSaveDataDialog::metaObject+0x180
QtCore4.dll!QMetaObject::activate+0x35d
QtGui4.dll!QDialogButtonBox::standardButton+0x11b
QtGui4.dll!QDialogButtonBox::qt_metacall+0x9d
QtCore4.dll!QMetaObject::activate+0x35d
QtGui4.dll!QAbstractButton::clicked+0x33
QtGui4.dll!QButtonGroup::checkedId+0x18f
QtGui4.dll!QButtonGroup::setId+0xc55
QtGui4.dll!QAbstractButton::mouseReleaseEvent+0x5a
QtGui4.dll!QWidget::event+0xcb
QtGui4.dll!QApplicationPrivate::notify_helper+0x102
QtGui4.dll!QApplication::notify+0x7e3
qSlicerBaseQTGUI.dll!qSlicerApplication::notify+0x1e
QtCore4.dll!QCoreApplication::notifyInternal+0x71
QtGui4.dll!QApplicationPrivate::sendMouseEvent+0x1e3
QtGui4.dll!QApplication::winFocus+0xe98
QtGui4.dll!QApplication::restoreOverrideCursor+0xbe6
USER32.dll!TranslateMessageEx+0x2a1
USER32.dll!TranslateMessage+0x1ea
QtCore4.dll!QEventDispatcherWin32::processEvents+0x545
QtGui4.dll!QApplicationPrivate::translateTouchEvent+0x815
QtCore4.dll!QEventLoop::exec+0x151
QtGui4.dll!QDialog::exec+0xed
qSlicerBaseQTGUI.dll!qSlicerSaveDataDialog::exec+0x2e
qSlicerBaseQTGUI.dll!qSlicerIOManager::openDialog+0x207
qSlicerBaseQTGUI.dll!qSlicerIOManager::openSaveDataDialog+0x63
qSlicerApp.dll!qSlicerAppMainWindowCore::qt_metacall+0xa7
QtCore4.dll!QMetaObject::activate+0x35d
QtGui4.dll!QAction::activate+0xe0
QtGui4.dll!QAction::event+0xaa
QtGui4.dll!QApplicationPrivate::notify_helper+0x102
QtGui4.dll!QApplication::notify+0x27c
qSlicerBaseQTGUI.dll!qSlicerApplication::notify+0x1e
QtCore4.dll!QCoreApplication::notifyInternal+0x71
QtGui4.dll!QKeySequence::operator!=+0x3ee
QtGui4.dll!QKeySequence::operator!=+0x2780
QtGui4.dll!QApplication::notify+0x407
qSlicerBaseQTGUI.dll!qSlicerApplication::notify+0x1e
QtCore4.dll!QCoreApplication::notifyInternal+0x71
QtGui4.dll!qt_translateKeyCode+0x101b
QtGui4.dll!qt_translateKeyCode+0x227f
QtGui4.dll!QApplication::restoreOverrideCursor+0x255c
USER32.dll!TranslateMessageEx+0x2a1
USER32.dll!TranslateMessage+0x1ea
QtCore4.dll!QEventDispatcherWin32::processEvents+0x545
QtGui4.dll!QApplicationPrivate::translateTouchEvent+0x815
QtCore4.dll!QEventLoop::exec+0x151
QtCore4.dll!QCoreApplication::exec+0xe0
SlicerApp-real.exe+0x2251
SlicerApp-real.exe+0x239b
SlicerApp-real.exe+0x2937
kernel32.dll!BaseThreadInitThunk+0xd
ntdll.dll!RtlUserThreadStart+0x21

TagsNo tags attached.

Activities

lassoan

lassoan

2013-10-05 03:26

developer   ~0010136

Randomly occurs with Win7 64-bit, NVidia NVS 4200M, Driver 296.20, DirectX 11.

Reported by others, too.

lassoan

lassoan

2013-10-05 05:30

developer   ~0010137

That infinite loop should be enabled in debug mode only, as some errors are not cleared after calling glGetError - this is a VTK bug, but not the root cause.

Infinite glGetError is most likely due to an invalid/uninitialized context:
http://www.graphicsgroups.com/6-opengl/510d9e088862d39a.htm
http://lists.qt.nokia.com/public/qt-interest/2011-January/030414.html

lassoan

lassoan

2013-10-05 16:40

developer   ~0010140

Done some more investigation:

  • The problem occurs if the layout is "Red slice only" (if this is the default view when Slicer starts and remains the current layout until the save). Just load the MRHead sample, save, and hang.
  • ctk::grabVTKWidget iterates through all childs of the selected widget, which includes invalid ones (probably the yellow and green slice viewers, which never rendered) => this should be fixed in CTK
  • In vtkOpenGLRenderWindow several methods try to clear the glError by calling glGetError() until no error is returned. The problem is that it always returns GL_INVALID_OPERATION, 0x0502 when the rendering context is not valid. => this should be fixed in VTK (allow infinite loop in debug mode only or have a maximum limit on how many times or for how long it tries to clear the error.

I don't have time for more investigation but I think this should be enough information for CTK developers to fix the issue and the problem should be probably reported to VTK developers as well.

lassoan

lassoan

2013-10-05 16:55

developer   ~0010141

Workaround for users until the problem is fixed: switch to the “Four-up” layout before saving the scene.

kikinis

kikinis

2013-10-06 05:52

developer   ~0010142

It does not happen to me on the mac.

pieper

pieper

2013-10-06 11:07

administrator   ~0010143

Also does not happen for me when using remote desktop to a windows 7 machine (tested 4.3.0).

lassoan

lassoan

2013-10-06 11:42

developer   ~0010144

I can reproduce with Slicer 4.3.0 over remote desktop on Win7:

  • start Slicer
  • switch to red slice layout
  • restart slicer
  • download mrhead sample
  • save scene
pieper

pieper

2013-10-06 11:52

administrator   ~0010145

Thanks Andras - yes, with the steps described in note 10143 I can replicate the issue on my machine via remote access.

It looks to me as though the problem is that there are QVTKWidget instances that are parented to the main window but have never been rendered (so they have no opengl context).

This loop can probably be fixed:

https://github.com/commontk/CTK/blob/master/Libs/Visualization/VTK/Widgets/ctkVTKWidgetsUtils.cpp#L48

It may be as simple as skipping QVTKWidgets that are not currently visible [1]

[1] http://qt-project.org/doc/qt-4.8/qwidget.html#visible-prop

lassoan

lassoan

2013-10-06 13:59

developer   ~0010147

Steve's suggested visibility check works perfectly (the screenshot is generated correctly and there is no hang). See the exact code change below.

There is a very similar loop in CTK\Libs\Widgets\ctkWidgetsUtils.cpp for QWidget. Probably this check should be added there, too.

diff --git a/Libs/Visualization/VTK/Widgets/ctkVTKWidgetsUtils.cpp b/Libs/Visualization/VTK/Widgets/ctkVTKWidgetsUtils.cpp
index 067ca6e..29812c9 100644
--- a/Libs/Visualization/VTK/Widgets/ctkVTKWidgetsUtils.cpp
+++ b/Libs/Visualization/VTK/Widgets/ctkVTKWidgetsUtils.cpp
@@ -47,6 +47,10 @@ QImage ctk::grabVTKWidget(QWidget widget, QRect rectangle)
painter.begin(&widgetImage);
foreach(QVTKWidget
vtkWidget, widget->findChildren<QVTKWidget*>())
{

  • if (!vtkWidget->isVisible())
  • {
  • continue;
  • }
    QRect subWidgetRect = QRect(vtkWidget->mapTo(widget, QPoint(0,0)), vtkWidget->size());
    if (!rectangle.intersects(subWidgetRect))
    {
pieper

pieper

2013-10-08 00:12

administrator   ~0010150

Fixed in CTK

https://github.com/commontk/CTK/commit/e4694372310dfa1de4bb654b427083f27d4d091c

Slicer updated:

https://github.com/Slicer/Slicer/commit/a1115337e986829e0792759702269ee77440067e

lassoan

lassoan

2013-10-19 08:15

developer   ~0010198

Tested on latest nightly on Win64 and it works correctly now.

jcfr

jcfr

2013-10-21 06:06

administrator   ~0010201

Backported to Slicer-4-3 branch.

See http://viewvc.slicer.org/viewvc.cgi/Slicer4?view=revision&amp;revision=22622

Related Changesets

Slicer: 2145-support-for-installing-extension-from-file a1115337

2013-10-08 03:18:45

pieper

Details Diff
BUG: 0003438 Avoid hang when saving due to non-visible widget grab

If the OpenGL context of the window is not correctly initialized,
then VTK cannot get a copy of the pixels and goes into an
infinite loop checking the GL error. This CTK version includes
a patch from Andras avoids this problem.

git-svn-id: http://svn.slicer.org/Slicer4/trunk@22605 3bd1e089-480b-0410-8dfb-8563597acbee
mod - SuperBuild/External_CTK.cmake Diff File

Issue History

Date Modified Username Field Change
2013-10-05 03:21 lassoan New Issue
2013-10-05 03:21 lassoan Status new => assigned
2013-10-05 03:21 lassoan Assigned To => kikinis
2013-10-05 03:26 lassoan Note Added: 0010136
2013-10-05 05:30 lassoan Note Added: 0010137
2013-10-05 05:55 kikinis Assigned To kikinis => jcfr
2013-10-05 16:40 lassoan Note Added: 0010140
2013-10-05 16:55 lassoan Note Added: 0010141
2013-10-06 05:52 kikinis Note Added: 0010142
2013-10-06 11:07 pieper Note Added: 0010143
2013-10-06 11:42 lassoan Note Added: 0010144
2013-10-06 11:52 pieper Note Added: 0010145
2013-10-06 13:59 lassoan Note Added: 0010147
2013-10-08 00:12 pieper Note Added: 0010150
2013-10-08 00:12 pieper Status assigned => resolved
2013-10-08 00:12 pieper Fixed in Version => Slicer 4.3.2
2013-10-08 00:12 pieper Resolution open => fixed
2013-10-19 08:15 lassoan Note Added: 0010198
2013-10-19 08:15 lassoan Status resolved => closed
2013-10-21 06:06 jcfr Target Version => Slicer 4.3.2
2013-10-21 06:06 jcfr Note Added: 0010201
2014-03-06 10:16 nicole Target Version Slicer 4.3.2 => Slicer 4.4.0
2014-03-06 10:17 nicole Fixed in Version Slicer 4.3.2 => Slicer 4.4.0
2017-06-07 23:27 pieper Changeset attached => Slicer 2145-support-for-installing-extension-from-file a1115337