Skip to content

Commit 92194ce

Browse files
committed
MatInfo = nil is not a good detection now
1 parent 396a47f commit 92194ce

File tree

1 file changed

+20
-4
lines changed

1 file changed

+20
-4
lines changed

castle_model_viewer.dpr

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2043,13 +2043,23 @@ procedure TEventsHandler.MenuClick(const MenuItem: TMenuItem);
20432043
Exit;
20442044
end;
20452045

2046-
MatInfo := SelectedItem^.State.MaterialInfo;
2047-
if MatInfo = nil then
2046+
{ We check "missing material" by looking at
2047+
Appearance and Appearance.Material.
2048+
Note: Looking at "SelectedItem^.State.MaterialInfo = nil"
2049+
would not be correct, as we now have TAppearanceNode.InternalInternalFallbackMaterialInfo
2050+
which means we may have MaterialInfo <> nil even
2051+
if Appearance.Material = nil. }
2052+
if (SelectedItem^.State.ShapeNode <> nil) and // X3D or VRML 2.0
2053+
( (SelectedItem^.State.Appearance = nil) or
2054+
(SelectedItem^.State.Appearance.Material = nil) ) then
20482055
begin
20492056
Window.MessageOK('No material assigned to this shape. Create a new material using one of "Reset To Default ... Material" menu items.', mtError);
20502057
Exit;
20512058
end;
20522059

2060+
MatInfo := SelectedItem^.State.MaterialInfo;
2061+
Check(MatInfo <> nil, 'Appearance.Material <> nil, so MaterialInfo should not be nil');
2062+
20532063
Color := MatInfo.EmissiveColor;
20542064
if Window.ColorDialog(Color) then
20552065
MatInfo.EmissiveColor := Color;
@@ -2066,13 +2076,19 @@ procedure TEventsHandler.MenuClick(const MenuItem: TMenuItem);
20662076
Exit;
20672077
end;
20682078

2069-
MatInfo := SelectedItem^.State.MaterialInfo;
2070-
if MatInfo = nil then
2079+
{ Same comment as in ChangeMaterialEmissiveColor:
2080+
Checking here "SelectedItem^.State.MaterialInfo = nil" would not be useful. }
2081+
if (SelectedItem^.State.ShapeNode <> nil) and // X3D or VRML 2.0
2082+
( (SelectedItem^.State.Appearance = nil) or
2083+
(SelectedItem^.State.Appearance.Material = nil) ) then
20712084
begin
20722085
Window.MessageOK('No material assigned to this shape. Create a new material using one of "Reset To Default ... Material" menu items.', mtError);
20732086
Exit;
20742087
end;
20752088

2089+
MatInfo := SelectedItem^.State.MaterialInfo;
2090+
Check(MatInfo <> nil, 'Appearance.Material <> nil, so MaterialInfo should not be nil');
2091+
20762092
Color := MatInfo.MainColor;
20772093
if Window.ColorDialog(Color) then
20782094
MatInfo.MainColor := Color;

0 commit comments

Comments
 (0)