Skip to content

Commit

Permalink
Merge pull request #80610 from lawnjelly/fix_tilemap_editor_plugin_cr…
Browse files Browse the repository at this point in the history
…ash2

Fix `TileMapEditorPlugin` crash by storing tilemap ID instead of pointer
  • Loading branch information
akien-mga committed Aug 14, 2023
2 parents bbefba0 + 356fc72 commit c78be12
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
7 changes: 7 additions & 0 deletions editor/plugins/tiles/tiles_editor_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,7 @@ void TileMapEditorPlugin::_tile_map_changed() {
}

void TileMapEditorPlugin::_update_tile_map() {
TileMap *tile_map = Object::cast_to<TileMap>(ObjectDB::get_instance(tile_map_id));
if (tile_map) {
Ref<TileSet> tile_set = tile_map->get_tileset();
if (tile_set.is_valid() && edited_tileset != tile_set->get_instance_id()) {
Expand All @@ -347,11 +348,17 @@ void TileMapEditorPlugin::_notification(int p_notification) {
}

void TileMapEditorPlugin::edit(Object *p_object) {
TileMap *tile_map = Object::cast_to<TileMap>(ObjectDB::get_instance(tile_map_id));
if (tile_map) {
tile_map->disconnect("changed", callable_mp(this, &TileMapEditorPlugin::_tile_map_changed));
}

tile_map = Object::cast_to<TileMap>(p_object);
if (tile_map) {
tile_map_id = tile_map->get_instance_id();
} else {
tile_map_id = ObjectID();
}

editor->edit(tile_map);
if (tile_map) {
Expand Down
2 changes: 1 addition & 1 deletion editor/plugins/tiles/tiles_editor_plugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ class TileMapEditorPlugin : public EditorPlugin {

TileMapEditor *editor = nullptr;
Button *button = nullptr;
TileMap *tile_map = nullptr;
ObjectID tile_map_id;

bool tile_map_changed_needs_update = false;
ObjectID edited_tileset;
Expand Down

0 comments on commit c78be12

Please sign in to comment.