Merge pull request #73892 from vonagam/fix-objects-indentity-compare

Core: Identity compare objects by id, not by pointers
This commit is contained in:
Rémi Verschelde 2023-02-25 01:03:54 +01:00 committed by GitHub
commit adbabfbaa9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 1 deletions

View File

@ -3499,7 +3499,7 @@ bool Variant::identity_compare(const Variant &p_variant) const {
switch (type) {
case OBJECT: {
return _get_obj().obj == p_variant._get_obj().obj;
return _get_obj().id == p_variant._get_obj().id;
} break;
case DICTIONARY: {

View File

@ -1056,6 +1056,14 @@ TEST_CASE("[Variant] Identity comparison") {
Variant obj_null_two_var = Variant((Object *)nullptr);
CHECK(obj_null_one_var.identity_compare(obj_null_one_var));
CHECK(obj_null_one_var.identity_compare(obj_null_two_var));
Object *freed_one = new Object();
Variant freed_one_var = freed_one;
delete freed_one;
Object *freed_two = new Object();
Variant freed_two_var = freed_two;
delete freed_two;
CHECK_FALSE(freed_one_var.identity_compare(freed_two_var));
}
TEST_CASE("[Variant] Nested array comparison") {