Skip to content

Commit

Permalink
BUG: Fixed crash when starting VR after showing a GUI widget
Browse files Browse the repository at this point in the history
  • Loading branch information
cpinter committed Jun 15, 2023
1 parent 85742ff commit 4d8d58e
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 6 deletions.
5 changes: 4 additions & 1 deletion GUIWidgets/VTKWidgets/vtkSlicerQWidgetRepresentation.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -270,5 +270,8 @@ void vtkSlicerQWidgetRepresentation::OnTextureModified(
self->PlaceWidget(bounds);

// Trigger rendering in view
self->GetViewNode()->Modified();
if (self->GetViewNode()->GetSelectable())
{
self->GetViewNode()->Modified();
}
}
6 changes: 6 additions & 0 deletions GUIWidgets/VTKWidgets/vtkSlicerQWidgetWidget.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -87,19 +87,25 @@ vtkSlicerMarkupsWidget* vtkSlicerQWidgetWidget::CreateInstance()const
void vtkSlicerQWidgetWidget::CreateDefaultRepresentation(
vtkMRMLMarkupsDisplayNode* markupsDisplayNode, vtkMRMLAbstractViewNode* viewNode, vtkRenderer* renderer)
{
//if (!viewNode->IsA("vtkMRMLVirtualRealityViewNode"))
if (vtkMRMLSliceNode::SafeDownCast(viewNode))
{
// There is no 2D representation of the GUI widget
return;
}

bool wasSelectable = viewNode->GetSelectable();
viewNode->SetSelectable(false); // Workaround to disable texture updates until setup is completed

vtkNew<vtkSlicerQWidgetRepresentation> rep;
this->SetRenderer(renderer);
this->SetRepresentation(rep);
rep->SetMarkupsDisplayNode(markupsDisplayNode);
rep->SetViewNode(viewNode);

rep->UpdateFromMRML(nullptr, 0); // full update

viewNode->SetSelectable(wasSelectable);
}

//------------------------------------------------------------------------------
Expand Down
4 changes: 3 additions & 1 deletion GUIWidgets/VTKWidgets/vtkSlicerQWidgetWidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,9 @@ class VTK_SLICER_GUIWIDGETS_MODULE_VTKWIDGETS_EXPORT vtkSlicerQWidgetWidget : pu
void CreateDefaultRepresentation(
vtkMRMLMarkupsDisplayNode* markupsDisplayNode, vtkMRMLAbstractViewNode* viewNode, vtkRenderer* renderer) override;

protected:
QPointF LastWidgetCoordinates;

protected:
vtkSlicerQWidgetWidget();
~vtkSlicerQWidgetWidget() override;
Expand All @@ -88,7 +91,6 @@ class VTK_SLICER_GUIWIDGETS_MODULE_VTKWIDGETS_EXPORT vtkSlicerQWidgetWidget : pu
Active
};
*/
QPointF LastWidgetCoordinates;

// These methods handle events
//static void SelectAction3D(vtkAbstractWidget*);
Expand Down
11 changes: 7 additions & 4 deletions VirtualReality/Widgets/qMRMLVirtualRealityView.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -334,11 +334,14 @@ void qMRMLVirtualRealityViewPrivate::updateWidgetFromMRML()

this->Renderer->SetTwoSidedLighting(this->MRMLVirtualRealityViewNode->GetTwoSidedLighting());

bool switchOnAllLights = this->MRMLVirtualRealityViewNode->GetBackLights();
for (int i = 2; i < this->Lights->GetNumberOfItems(); i++)
if (this->Lights)
{
vtkLight* light = vtkLight::SafeDownCast(this->Lights->GetItemAsObject(i));
light->SetSwitch(switchOnAllLights);
bool switchOnAllLights = this->MRMLVirtualRealityViewNode->GetBackLights();
for (int i = 2; i < this->Lights->GetNumberOfItems(); i++)
{
vtkLight* light = vtkLight::SafeDownCast(this->Lights->GetItemAsObject(i));
light->SetSwitch(switchOnAllLights);
}
}

this->Renderer->SetUseDepthPeeling(this->MRMLVirtualRealityViewNode->GetUseDepthPeeling() != 0);
Expand Down

0 comments on commit 4d8d58e

Please sign in to comment.