Skip to content

Commit 18c7481

Browse files
committed
Fix crash when attempting to draw a base node for a building that has a bib with an empty first frame
1 parent e741426 commit 18c7481

1 file changed

Lines changed: 26 additions & 22 deletions

File tree

src/TSMapEditor/Rendering/MapView.cs

Lines changed: 26 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1043,7 +1043,7 @@ private void DrawBaseNode(GraphicalBaseNode graphicalBaseNode)
10431043
int yDrawOffset = Constants.CellSizeY / -2;
10441044
int frameIndex = 0;
10451045

1046-
if ((graphics == null || graphics.GetFrame(frameIndex) == null) && bibGraphics == null)
1046+
if ((graphics == null || graphics.GetFrame(frameIndex) == null) && (bibGraphics == null || bibGraphics.GetFrame(0) == null))
10471047
{
10481048
DrawStringWithShadow(iniName, 1, drawPoint.ToXNAVector(), replacementColor, 1.0f);
10491049
return;
@@ -1054,31 +1054,35 @@ private void DrawBaseNode(GraphicalBaseNode graphicalBaseNode)
10541054
if (bibGraphics != null)
10551055
{
10561056
PositionedTexture bibFrame = bibGraphics.GetFrame(0);
1057-
texture = bibFrame.Texture;
10581057

1059-
int bibFinalDrawPointX = drawPoint.X - bibFrame.ShapeWidth / 2 + bibFrame.OffsetX + Constants.CellSizeX / 2;
1060-
int bibFinalDrawPointY = drawPoint.Y - bibFrame.ShapeHeight / 2 + bibFrame.OffsetY + Constants.CellSizeY / 2 + yDrawOffset;
1058+
if (bibFrame != null && bibFrame.Texture != null)
1059+
{
1060+
texture = bibFrame.Texture;
10611061

1062-
palettedColorDrawEffect.Parameters["UseRemap"].SetValue(false);
1063-
palettedColorDrawEffect.Parameters["PaletteTexture"].SetValue(bibGraphics.GetPaletteTexture(EditorState.IsLighting));
1062+
int bibFinalDrawPointX = drawPoint.X - bibFrame.ShapeWidth / 2 + bibFrame.OffsetX + Constants.CellSizeX / 2;
1063+
int bibFinalDrawPointY = drawPoint.Y - bibFrame.ShapeHeight / 2 + bibFrame.OffsetY + Constants.CellSizeY / 2 + yDrawOffset;
10641064

1065-
DrawTexture(texture, new Rectangle(
1066-
bibFinalDrawPointX, bibFinalDrawPointY,
1067-
texture.Width, texture.Height),
1068-
null,nonRemapBaseNodeShade,
1069-
0f, Vector2.Zero, SpriteEffects.None, 0f);
1065+
palettedColorDrawEffect.Parameters["UseRemap"].SetValue(false);
1066+
palettedColorDrawEffect.Parameters["PaletteTexture"].SetValue(bibGraphics.GetPaletteTexture(EditorState.IsLighting));
10701067

1071-
if (bibGraphics.HasRemapFrames())
1072-
{
1073-
palettedColorDrawEffect.Parameters["UseRemap"].SetValue(true);
1074-
DrawTexture(bibGraphics.GetRemapFrame(0).Texture,
1075-
new Rectangle(bibFinalDrawPointX, bibFinalDrawPointY, texture.Width, texture.Height),
1076-
null,
1077-
remapColor,
1078-
0f,
1079-
Vector2.Zero,
1080-
SpriteEffects.None,
1081-
0f);
1068+
DrawTexture(texture, new Rectangle(
1069+
bibFinalDrawPointX, bibFinalDrawPointY,
1070+
texture.Width, texture.Height),
1071+
null, nonRemapBaseNodeShade,
1072+
0f, Vector2.Zero, SpriteEffects.None, 0f);
1073+
1074+
if (bibGraphics.HasRemapFrames())
1075+
{
1076+
palettedColorDrawEffect.Parameters["UseRemap"].SetValue(true);
1077+
DrawTexture(bibGraphics.GetRemapFrame(0).Texture,
1078+
new Rectangle(bibFinalDrawPointX, bibFinalDrawPointY, texture.Width, texture.Height),
1079+
null,
1080+
remapColor,
1081+
0f,
1082+
Vector2.Zero,
1083+
SpriteEffects.None,
1084+
0f);
1085+
}
10821086
}
10831087
}
10841088

0 commit comments

Comments
 (0)