Merge pull request #78561 from groud/fix_crash_in_TileSetAltasSourceEditor

Fixes crash in TileSetAtlasSourceEditor
This commit is contained in:
Rémi Verschelde 2023-06-22 18:31:38 +02:00
commit c7e4dc1df7
No known key found for this signature in database
GPG key ID: C3336907360768E1
2 changed files with 22 additions and 22 deletions

View file

@ -87,7 +87,7 @@ bool TileSetAtlasSourceEditor::TileSetAtlasSourceProxyObject::_set(const StringN
} }
bool TileSetAtlasSourceEditor::TileSetAtlasSourceProxyObject::_get(const StringName &p_name, Variant &r_ret) const { bool TileSetAtlasSourceEditor::TileSetAtlasSourceProxyObject::_get(const StringName &p_name, Variant &r_ret) const {
if (!tile_set_atlas_source) { if (!tile_set_atlas_source.is_valid()) {
return false; return false;
} }
if (p_name == "id") { if (p_name == "id") {
@ -119,8 +119,8 @@ void TileSetAtlasSourceEditor::TileSetAtlasSourceProxyObject::_bind_methods() {
ADD_SIGNAL(MethodInfo("changed", PropertyInfo(Variant::STRING, "what"))); ADD_SIGNAL(MethodInfo("changed", PropertyInfo(Variant::STRING, "what")));
} }
void TileSetAtlasSourceEditor::TileSetAtlasSourceProxyObject::edit(Ref<TileSet> p_tile_set, TileSetAtlasSource *p_tile_set_atlas_source, int p_source_id) { void TileSetAtlasSourceEditor::TileSetAtlasSourceProxyObject::edit(Ref<TileSet> p_tile_set, Ref<TileSetAtlasSource> p_tile_set_atlas_source, int p_source_id) {
ERR_FAIL_COND(!p_tile_set_atlas_source); ERR_FAIL_COND(!p_tile_set_atlas_source.is_valid());
ERR_FAIL_COND(p_source_id < 0); ERR_FAIL_COND(p_source_id < 0);
ERR_FAIL_COND(p_tile_set.is_valid() && p_tile_set->get_source(p_source_id) != p_tile_set_atlas_source); ERR_FAIL_COND(p_tile_set.is_valid() && p_tile_set->get_source(p_source_id) != p_tile_set_atlas_source);
@ -129,7 +129,7 @@ void TileSetAtlasSourceEditor::TileSetAtlasSourceProxyObject::edit(Ref<TileSet>
} }
// Disconnect to changes. // Disconnect to changes.
if (tile_set_atlas_source) { if (tile_set_atlas_source.is_valid()) {
tile_set_atlas_source->disconnect(CoreStringNames::get_singleton()->property_list_changed, callable_mp((Object *)this, &Object::notify_property_list_changed)); tile_set_atlas_source->disconnect(CoreStringNames::get_singleton()->property_list_changed, callable_mp((Object *)this, &Object::notify_property_list_changed));
} }
@ -138,7 +138,7 @@ void TileSetAtlasSourceEditor::TileSetAtlasSourceProxyObject::edit(Ref<TileSet>
source_id = p_source_id; source_id = p_source_id;
// Connect to changes. // Connect to changes.
if (tile_set_atlas_source) { if (tile_set_atlas_source.is_valid()) {
if (!tile_set_atlas_source->is_connected(CoreStringNames::get_singleton()->property_list_changed, callable_mp((Object *)this, &Object::notify_property_list_changed))) { if (!tile_set_atlas_source->is_connected(CoreStringNames::get_singleton()->property_list_changed, callable_mp((Object *)this, &Object::notify_property_list_changed))) {
tile_set_atlas_source->connect(CoreStringNames::get_singleton()->property_list_changed, callable_mp((Object *)this, &Object::notify_property_list_changed)); tile_set_atlas_source->connect(CoreStringNames::get_singleton()->property_list_changed, callable_mp((Object *)this, &Object::notify_property_list_changed));
} }
@ -149,7 +149,7 @@ void TileSetAtlasSourceEditor::TileSetAtlasSourceProxyObject::edit(Ref<TileSet>
// -- Proxy object used by the tile inspector -- // -- Proxy object used by the tile inspector --
bool TileSetAtlasSourceEditor::AtlasTileProxyObject::_set(const StringName &p_name, const Variant &p_value) { bool TileSetAtlasSourceEditor::AtlasTileProxyObject::_set(const StringName &p_name, const Variant &p_value) {
if (!tile_set_atlas_source) { if (!tile_set_atlas_source.is_valid()) {
return false; return false;
} }
@ -300,7 +300,7 @@ bool TileSetAtlasSourceEditor::AtlasTileProxyObject::_set(const StringName &p_na
} }
bool TileSetAtlasSourceEditor::AtlasTileProxyObject::_get(const StringName &p_name, Variant &r_ret) const { bool TileSetAtlasSourceEditor::AtlasTileProxyObject::_get(const StringName &p_name, Variant &r_ret) const {
if (!tile_set_atlas_source) { if (!tile_set_atlas_source.is_valid()) {
return false; return false;
} }
@ -384,7 +384,7 @@ bool TileSetAtlasSourceEditor::AtlasTileProxyObject::_get(const StringName &p_na
} }
void TileSetAtlasSourceEditor::AtlasTileProxyObject::_get_property_list(List<PropertyInfo> *p_list) const { void TileSetAtlasSourceEditor::AtlasTileProxyObject::_get_property_list(List<PropertyInfo> *p_list) const {
if (!tile_set_atlas_source) { if (!tile_set_atlas_source.is_valid()) {
return; return;
} }
@ -492,8 +492,8 @@ void TileSetAtlasSourceEditor::AtlasTileProxyObject::_get_property_list(List<Pro
} }
} }
void TileSetAtlasSourceEditor::AtlasTileProxyObject::edit(TileSetAtlasSource *p_tile_set_atlas_source, RBSet<TileSelection> p_tiles) { void TileSetAtlasSourceEditor::AtlasTileProxyObject::edit(Ref<TileSetAtlasSource> p_tile_set_atlas_source, RBSet<TileSelection> p_tiles) {
ERR_FAIL_COND(!p_tile_set_atlas_source); ERR_FAIL_COND(!p_tile_set_atlas_source.is_valid());
ERR_FAIL_COND(p_tiles.is_empty()); ERR_FAIL_COND(p_tiles.is_empty());
for (const TileSelection &E : p_tiles) { for (const TileSelection &E : p_tiles) {
ERR_FAIL_COND(E.tile == TileSetSource::INVALID_ATLAS_COORDS); ERR_FAIL_COND(E.tile == TileSetSource::INVALID_ATLAS_COORDS);
@ -505,7 +505,7 @@ void TileSetAtlasSourceEditor::AtlasTileProxyObject::edit(TileSetAtlasSource *p_
const Vector2i &coords = E.tile; const Vector2i &coords = E.tile;
const int &alternative = E.alternative; const int &alternative = E.alternative;
if (tile_set_atlas_source && tile_set_atlas_source->has_tile(coords) && tile_set_atlas_source->has_alternative_tile(coords, alternative)) { if (tile_set_atlas_source.is_valid() && tile_set_atlas_source->has_tile(coords) && tile_set_atlas_source->has_alternative_tile(coords, alternative)) {
TileData *tile_data = tile_set_atlas_source->get_tile_data(coords, alternative); TileData *tile_data = tile_set_atlas_source->get_tile_data(coords, alternative);
if (tile_data->is_connected(CoreStringNames::get_singleton()->property_list_changed, callable_mp((Object *)this, &Object::notify_property_list_changed))) { if (tile_data->is_connected(CoreStringNames::get_singleton()->property_list_changed, callable_mp((Object *)this, &Object::notify_property_list_changed))) {
tile_data->disconnect(CoreStringNames::get_singleton()->property_list_changed, callable_mp((Object *)this, &Object::notify_property_list_changed)); tile_data->disconnect(CoreStringNames::get_singleton()->property_list_changed, callable_mp((Object *)this, &Object::notify_property_list_changed));
@ -2153,10 +2153,10 @@ void TileSetAtlasSourceEditor::_undo_redo_inspector_callback(Object *p_undo_redo
TileSetAtlasSourceProxyObject *atlas_source_proxy = Object::cast_to<TileSetAtlasSourceProxyObject>(p_edited); TileSetAtlasSourceProxyObject *atlas_source_proxy = Object::cast_to<TileSetAtlasSourceProxyObject>(p_edited);
if (atlas_source_proxy) { if (atlas_source_proxy) {
TileSetAtlasSource *atlas_source = atlas_source_proxy->get_edited(); Ref<TileSetAtlasSource> atlas_source = atlas_source_proxy->get_edited();
ERR_FAIL_COND(!atlas_source); ERR_FAIL_COND(!atlas_source.is_valid());
UndoRedo *internal_undo_redo = undo_redo_man->get_history_for_object(atlas_source).undo_redo; UndoRedo *internal_undo_redo = undo_redo_man->get_history_for_object(atlas_source.ptr()).undo_redo;
internal_undo_redo->start_force_keep_in_merge_ends(); internal_undo_redo->start_force_keep_in_merge_ends();
PackedVector2Array arr; PackedVector2Array arr;
@ -2180,7 +2180,7 @@ void TileSetAtlasSourceEditor::_undo_redo_inspector_callback(Object *p_undo_redo
String prefix = vformat("%d:%d/", coords.x, coords.y); String prefix = vformat("%d:%d/", coords.x, coords.y);
for (PropertyInfo pi : properties) { for (PropertyInfo pi : properties) {
if (pi.name.begins_with(prefix)) { if (pi.name.begins_with(prefix)) {
ADD_UNDO(atlas_source, pi.name); ADD_UNDO(atlas_source.ptr(), pi.name);
} }
} }
} }
@ -2704,7 +2704,7 @@ void EditorPropertyTilePolygon::update_property() {
ERR_FAIL_COND(!atlas_tile_proxy_object); ERR_FAIL_COND(!atlas_tile_proxy_object);
ERR_FAIL_COND(atlas_tile_proxy_object->get_edited_tiles().is_empty()); ERR_FAIL_COND(atlas_tile_proxy_object->get_edited_tiles().is_empty());
TileSetAtlasSource *tile_set_atlas_source = atlas_tile_proxy_object->get_edited_tile_set_atlas_source(); Ref<TileSetAtlasSource> tile_set_atlas_source = atlas_tile_proxy_object->get_edited_tile_set_atlas_source();
generic_tile_polygon_editor->set_tile_set(Ref<TileSet>(tile_set_atlas_source->get_tile_set())); generic_tile_polygon_editor->set_tile_set(Ref<TileSet>(tile_set_atlas_source->get_tile_set()));
// Set the background // Set the background

View file

@ -66,7 +66,7 @@ public:
private: private:
Ref<TileSet> tile_set; Ref<TileSet> tile_set;
TileSetAtlasSource *tile_set_atlas_source = nullptr; Ref<TileSetAtlasSource> tile_set_atlas_source;
int source_id = TileSet::INVALID_SOURCE; int source_id = TileSet::INVALID_SOURCE;
protected: protected:
@ -79,8 +79,8 @@ public:
void set_id(int p_id); void set_id(int p_id);
int get_id() const; int get_id() const;
void edit(Ref<TileSet> p_tile_set, TileSetAtlasSource *p_tile_set_atlas_source, int p_source_id); void edit(Ref<TileSet> p_tile_set, Ref<TileSetAtlasSource> p_tile_set_atlas_source, int p_source_id);
TileSetAtlasSource *get_edited() { return tile_set_atlas_source; }; Ref<TileSetAtlasSource> get_edited() { return tile_set_atlas_source; };
}; };
// -- Proxy object for a tile, needed by the inspector -- // -- Proxy object for a tile, needed by the inspector --
@ -90,7 +90,7 @@ public:
private: private:
TileSetAtlasSourceEditor *tiles_set_atlas_source_editor = nullptr; TileSetAtlasSourceEditor *tiles_set_atlas_source_editor = nullptr;
TileSetAtlasSource *tile_set_atlas_source = nullptr; Ref<TileSetAtlasSource> tile_set_atlas_source;
RBSet<TileSelection> tiles = RBSet<TileSelection>(); RBSet<TileSelection> tiles = RBSet<TileSelection>();
protected: protected:
@ -101,11 +101,11 @@ public:
static void _bind_methods(); static void _bind_methods();
public: public:
TileSetAtlasSource *get_edited_tile_set_atlas_source() const { return tile_set_atlas_source; }; Ref<TileSetAtlasSource> get_edited_tile_set_atlas_source() const { return tile_set_atlas_source; };
RBSet<TileSelection> get_edited_tiles() const { return tiles; }; RBSet<TileSelection> get_edited_tiles() const { return tiles; };
// Update the proxyed object. // Update the proxyed object.
void edit(TileSetAtlasSource *p_tile_set_atlas_source, RBSet<TileSelection> p_tiles = RBSet<TileSelection>()); void edit(Ref<TileSetAtlasSource> p_tile_set_atlas_source, RBSet<TileSelection> p_tiles = RBSet<TileSelection>());
AtlasTileProxyObject(TileSetAtlasSourceEditor *p_tiles_set_atlas_source_editor) { AtlasTileProxyObject(TileSetAtlasSourceEditor *p_tiles_set_atlas_source_editor) {
tiles_set_atlas_source_editor = p_tiles_set_atlas_source_editor; tiles_set_atlas_source_editor = p_tiles_set_atlas_source_editor;