Skip to content
This repository was archived by the owner on Jul 11, 2025. It is now read-only.

Commit e7d6e55

Browse files
committed
Fix possible null reference and initialize selected area if empty.
1 parent dff2722 commit e7d6e55

File tree

3 files changed

+28
-1
lines changed

3 files changed

+28
-1
lines changed

Source/Plugins/Tilemaps/Editor/CamViewStates/TilemapEditorCamViewState.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -609,6 +609,7 @@ private void DeselectToolInInspector()
609609
private void MoveTilePaletteSelection(Keys keyPressed)
610610
{
611611
TilemapToolSourcePalette sourcePalette = TilemapsEditorPlugin.Instance.PeekTilePalette();
612+
if (sourcePalette == null) return;
612613

613614
if (keyPressed == Keys.Up)
614615
{
@@ -630,6 +631,7 @@ private void MoveTilePaletteSelection(Keys keyPressed)
630631
private void ExpandTilePaletteSelection(Keys keyPressed)
631632
{
632633
TilemapToolSourcePalette sourcePalette = TilemapsEditorPlugin.Instance.PeekTilePalette();
634+
if (sourcePalette == null) return;
633635

634636
if (keyPressed == Keys.Up)
635637
{
@@ -651,6 +653,7 @@ private void ExpandTilePaletteSelection(Keys keyPressed)
651653
private void ShrinkTilePaletteSelection(Keys keyPressed)
652654
{
653655
TilemapToolSourcePalette sourcePalette = TilemapsEditorPlugin.Instance.PeekTilePalette();
656+
if (sourcePalette == null) return;
654657

655658
if (keyPressed == Keys.Up)
656659
{

Source/Plugins/Tilemaps/Editor/Modules/SourcePaletteTilesetView.cs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,12 @@ public IReadOnlyGrid<Tile> SelectedTiles
7878
}
7979
internal void TranslateSelectedArea(int offsetX, int offsetY)
8080
{
81+
if (this.selectedArea.IsEmpty)
82+
{
83+
this.InitializeSelectedArea();
84+
return;
85+
}
86+
8187
int newX = MathF.Clamp(this.selectedArea.X + offsetX, 0, this.DisplayedTileCount.X - this.selectedArea.Width);
8288
int newY = MathF.Clamp(this.selectedArea.Y + offsetY, 0, this.DisplayedTileCount.Y - this.selectedArea.Height);
8389

@@ -87,6 +93,12 @@ internal void TranslateSelectedArea(int offsetX, int offsetY)
8793
}
8894
internal void ExpandSelectedArea(int diffX, int diffY)
8995
{
96+
if (this.selectedArea.IsEmpty)
97+
{
98+
this.InitializeSelectedArea();
99+
return;
100+
}
101+
90102
int newX = MathF.Max(this.selectedArea.X + MathF.Min(diffX, 0), 0);
91103
int newY = MathF.Max(this.selectedArea.Y + MathF.Min(diffY, 0), 0);
92104

@@ -104,6 +116,12 @@ internal void ExpandSelectedArea(int diffX, int diffY)
104116
}
105117
public void ShrinkSelectedArea(int diffX, int diffY)
106118
{
119+
if (this.selectedArea.IsEmpty)
120+
{
121+
this.InitializeSelectedArea();
122+
return;
123+
}
124+
107125
int newX = MathF.Min(this.selectedArea.X + MathF.Max(diffX, 0),
108126
this.selectedArea.X + this.selectedArea.Width - 1);
109127
int newY = MathF.Min(this.selectedArea.Y + MathF.Max(diffY, 0),
@@ -483,6 +501,12 @@ private void UpdateSelectedTiles()
483501
}
484502
}
485503
}
504+
private void InitializeSelectedArea()
505+
{
506+
Rectangle rect = new Rectangle(0, 0, 1, 1);
507+
this.SelectedArea = rect;
508+
this.RaiseSelectedAreaEditingFinished();
509+
}
486510

487511
private void RaiseSelectedAreaEditingFinished()
488512
{

Source/Plugins/Tilemaps/Editor/Modules/TilemapToolSourcePalette.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public TilemapToolSourcePalette()
4545
}
4646

4747
/// <summary>
48-
/// Translates the selected area in the source palette by a number of tiles in the X and Y axes.
48+
/// Translates the selected area in the source palette by a number of tiles along the X and Y axes.
4949
/// </summary>
5050
public void TranslateSelectedArea(int offsetX, int offsetY)
5151
{

0 commit comments

Comments
 (0)