From c7b6cf9f6d8fe9e6f07b548ca0443562388d3b21 Mon Sep 17 00:00:00 2001 From: kobewi Date: Fri, 19 Apr 2024 18:05:48 +0200 Subject: [PATCH] Don't store TileMapLayer data if empty --- doc/classes/TileMapLayer.xml | 2 +- scene/2d/tile_map_layer.cpp | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/doc/classes/TileMapLayer.xml b/doc/classes/TileMapLayer.xml index da716a8fe33d..0513a7934cc5 100644 --- a/doc/classes/TileMapLayer.xml +++ b/doc/classes/TileMapLayer.xml @@ -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. - + The raw tile map data as a byte array. diff --git a/scene/2d/tile_map_layer.cpp b/scene/2d/tile_map_layer.cpp index 873cfeebda1e..ab3c48562c7c 100644 --- a/scene/2d/tile_map_layer.cpp +++ b/scene/2d/tile_map_layer.cpp @@ -2588,6 +2588,11 @@ TileMapLayer::HighlightMode TileMapLayer::get_highlight_mode() const { } void TileMapLayer::set_tile_map_data_from_array(const Vector &p_data) { + if (p_data.is_empty()) { + clear(); + return; + } + const int cell_data_struct_size = 12; int size = p_data.size(); @@ -2630,6 +2635,10 @@ Vector TileMapLayer::get_tile_map_data_as_array() const { const int cell_data_struct_size = 12; Vector 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();