Skip to content

Commit af79a28

Browse files
authored
Merge pull request #147 from zhaozhiwen/fix/137-visattr-null-guard
Guard against null GetVisAttributes() in G4Ttree_item constructor
2 parents b464ae4 + 3f8d5d7 commit af79a28

1 file changed

Lines changed: 12 additions & 12 deletions

File tree

gemc/gtree/gtree.cc

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -197,18 +197,18 @@ G4Ttree_item::G4Ttree_item(G4Volume* g4volume, const GVolume* gvolume) {
197197

198198
// Read visualization attributes from the logical volume.
199199
auto visAttributes = lvolume->GetVisAttributes();
200-
auto gcolor = visAttributes->GetColour();
201-
202-
double red = gcolor.GetRed();
203-
double green = gcolor.GetGreen();
204-
double blue = gcolor.GetBlue();
205-
auto alpha = gcolor.GetAlpha();
206-
207-
color = QColor::fromRgbF(red, green, blue);
208-
209-
opacity = alpha;
210-
211-
is_visible = visAttributes->IsVisible();
200+
if (visAttributes != nullptr) {
201+
auto gcolor = visAttributes->GetColour();
202+
color = QColor::fromRgbF(gcolor.GetRed(), gcolor.GetGreen(), gcolor.GetBlue());
203+
opacity = gcolor.GetAlpha();
204+
is_visible = visAttributes->IsVisible();
205+
}
206+
else {
207+
// No vis attributes assigned (e.g. imported CAD/GDML volumes): fall back to opaque white, visible.
208+
color = QColor::fromRgbF(1.0, 1.0, 1.0);
209+
opacity = 1.0;
210+
is_visible = true;
211+
}
212212

213213
// Store scaled physics quantities for display (g, cm3, g/cm3).
214214
mass = lvolume->GetMass(false, true) / (CLHEP::g);

0 commit comments

Comments
 (0)