You've already forked godot
mirror of
https://github.com/godotengine/godot.git
synced 2025-11-11 13:10:58 +00:00
Fix TileMapEditorPlugin crash by storing tilemap ID instead of pointer
Store the tilemap ObjectID instead of raw pointer, and check it is valid before access.
This commit is contained in:
@@ -325,6 +325,7 @@ void TileMapEditorPlugin::_tile_map_changed() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void TileMapEditorPlugin::_update_tile_map() {
|
void TileMapEditorPlugin::_update_tile_map() {
|
||||||
|
TileMap *tile_map = Object::cast_to<TileMap>(ObjectDB::get_instance(tile_map_id));
|
||||||
if (tile_map) {
|
if (tile_map) {
|
||||||
Ref<TileSet> tile_set = tile_map->get_tileset();
|
Ref<TileSet> tile_set = tile_map->get_tileset();
|
||||||
if (tile_set.is_valid() && edited_tileset != tile_set->get_instance_id()) {
|
if (tile_set.is_valid() && edited_tileset != tile_set->get_instance_id()) {
|
||||||
@@ -347,11 +348,17 @@ void TileMapEditorPlugin::_notification(int p_notification) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void TileMapEditorPlugin::edit(Object *p_object) {
|
void TileMapEditorPlugin::edit(Object *p_object) {
|
||||||
|
TileMap *tile_map = Object::cast_to<TileMap>(ObjectDB::get_instance(tile_map_id));
|
||||||
if (tile_map) {
|
if (tile_map) {
|
||||||
tile_map->disconnect("changed", callable_mp(this, &TileMapEditorPlugin::_tile_map_changed));
|
tile_map->disconnect("changed", callable_mp(this, &TileMapEditorPlugin::_tile_map_changed));
|
||||||
}
|
}
|
||||||
|
|
||||||
tile_map = Object::cast_to<TileMap>(p_object);
|
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);
|
editor->edit(tile_map);
|
||||||
if (tile_map) {
|
if (tile_map) {
|
||||||
|
|||||||
@@ -115,7 +115,7 @@ class TileMapEditorPlugin : public EditorPlugin {
|
|||||||
|
|
||||||
TileMapEditor *editor = nullptr;
|
TileMapEditor *editor = nullptr;
|
||||||
Button *button = nullptr;
|
Button *button = nullptr;
|
||||||
TileMap *tile_map = nullptr;
|
ObjectID tile_map_id;
|
||||||
|
|
||||||
bool tile_map_changed_needs_update = false;
|
bool tile_map_changed_needs_update = false;
|
||||||
ObjectID edited_tileset;
|
ObjectID edited_tileset;
|
||||||
|
|||||||
Reference in New Issue
Block a user