From 3f8d5d7321a31f9425cf0fde998939249c4f818f Mon Sep 17 00:00:00 2001 From: Zhiwen Zhao Date: Fri, 12 Jun 2026 22:33:19 -0400 Subject: [PATCH] Guard against null GetVisAttributes() in G4Ttree_item constructor G4LogicalVolume::GetVisAttributes() returns nullptr for volumes with no vis attributes (e.g. imported CAD/GDML geometries), and the constructor dereferenced it unconditionally, crashing the geometry tree viewer. Add a null check with an opaque-white, visible fallback. Fixes #137 Co-Authored-By: Claude Fable 5 --- gemc/gtree/gtree.cc | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/gemc/gtree/gtree.cc b/gemc/gtree/gtree.cc index 116d93f1..58cebc29 100644 --- a/gemc/gtree/gtree.cc +++ b/gemc/gtree/gtree.cc @@ -197,18 +197,18 @@ G4Ttree_item::G4Ttree_item(G4Volume* g4volume, const GVolume* gvolume) { // Read visualization attributes from the logical volume. auto visAttributes = lvolume->GetVisAttributes(); - auto gcolor = visAttributes->GetColour(); - - double red = gcolor.GetRed(); - double green = gcolor.GetGreen(); - double blue = gcolor.GetBlue(); - auto alpha = gcolor.GetAlpha(); - - color = QColor::fromRgbF(red, green, blue); - - opacity = alpha; - - is_visible = visAttributes->IsVisible(); + if (visAttributes != nullptr) { + auto gcolor = visAttributes->GetColour(); + color = QColor::fromRgbF(gcolor.GetRed(), gcolor.GetGreen(), gcolor.GetBlue()); + opacity = gcolor.GetAlpha(); + is_visible = visAttributes->IsVisible(); + } + else { + // No vis attributes assigned (e.g. imported CAD/GDML volumes): fall back to opaque white, visible. + color = QColor::fromRgbF(1.0, 1.0, 1.0); + opacity = 1.0; + is_visible = true; + } // Store scaled physics quantities for display (g, cm3, g/cm3). mass = lvolume->GetMass(false, true) / (CLHEP::g);