From 5a73b1cacb5464812f1fdb9e9f30755dcf2a7ea3 Mon Sep 17 00:00:00 2001
From: Fabian Paus <fabian.paus@kit.edu>
Date: Wed, 5 Jan 2022 11:33:45 +0100
Subject: [PATCH] ArViz: Prevent crash if layer with selected element is hidden

---
 source/RobotAPI/components/ArViz/Coin/Visualizer.cpp | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/source/RobotAPI/components/ArViz/Coin/Visualizer.cpp b/source/RobotAPI/components/ArViz/Coin/Visualizer.cpp
index 3ef94f45d..0b5826a89 100644
--- a/source/RobotAPI/components/ArViz/Coin/Visualizer.cpp
+++ b/source/RobotAPI/components/ArViz/Coin/Visualizer.cpp
@@ -507,6 +507,12 @@ namespace coin
             // Layer is currently visible
             if (!visible)
             {
+                // If we hide a layer wit a selected element, Coin will crash during rendering
+                // So we check if the selected element is in the layer to be hidden
+                if (selectedElement && selectedElement->layer == id)
+                {
+                    selection->deselectAll();
+                }
                 root->removeChild(childIndex);
             }
         }
-- 
GitLab