Skip to content

Commit

Permalink
Merge pull request #90907 from KoBeWi/null_tile_exception
Browse files Browse the repository at this point in the history
Don't store TileMapLayer data if empty
  • Loading branch information
akien-mga committed Apr 22, 2024
2 parents f0db317 + c7b6cf9 commit 7599be9
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
2 changes: 1 addition & 1 deletion doc/classes/TileMapLayer.xml
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@
The quadrant size does not apply on a Y-sorted [TileMapLayer], as tiles are be grouped by Y position instead in that case.
[b]Note:[/b] As quadrants are created according to the map's coordinate system, the quadrant's "square shape" might not look like square in the [TileMapLayer]'s local coordinate system.
</member>
<member name="tile_map_data" type="PackedByteArray" setter="set_tile_map_data_from_array" getter="get_tile_map_data_as_array" default="PackedByteArray(&quot;AAA=&quot;)">
<member name="tile_map_data" type="PackedByteArray" setter="set_tile_map_data_from_array" getter="get_tile_map_data_as_array" default="PackedByteArray()">
The raw tile map data as a byte array.
</member>
<member name="tile_set" type="TileSet" setter="set_tile_set" getter="get_tile_set">
Expand Down
9 changes: 9 additions & 0 deletions scene/2d/tile_map_layer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2588,6 +2588,11 @@ TileMapLayer::HighlightMode TileMapLayer::get_highlight_mode() const {
}

void TileMapLayer::set_tile_map_data_from_array(const Vector<uint8_t> &p_data) {
if (p_data.is_empty()) {
clear();
return;
}

const int cell_data_struct_size = 12;

int size = p_data.size();
Expand Down Expand Up @@ -2630,6 +2635,10 @@ Vector<uint8_t> TileMapLayer::get_tile_map_data_as_array() const {
const int cell_data_struct_size = 12;

Vector<uint8_t> tile_map_data_array;
if (tile_map_layer_data.is_empty()) {
return tile_map_data_array;
}

tile_map_data_array.resize(2 + tile_map_layer_data.size() * cell_data_struct_size);
uint8_t *ptr = tile_map_data_array.ptrw();

Expand Down

0 comments on commit 7599be9

Please sign in to comment.