mirror of
https://github.com/godotengine/godot.git
synced 2025-10-19 16:03:29 +00:00
Object::call()
prevent debug lock accessing dangling pointer
Self deleting an object within a call was leading to crashes due to referencing freed memory, due to a raw pointer stored in the debug lock.
Co-authored-by: RandomShaper <pedrojrulez@gmail.com>
(cherry picked from commit 0ccd559d17
)
This commit is contained in:
parent
cc39cf3e29
commit
c8317fc926
1 changed files with 7 additions and 4 deletions
|
@ -43,14 +43,17 @@
|
||||||
#ifdef DEBUG_ENABLED
|
#ifdef DEBUG_ENABLED
|
||||||
|
|
||||||
struct _ObjectDebugLock {
|
struct _ObjectDebugLock {
|
||||||
Object *obj;
|
ObjectID obj_id;
|
||||||
|
|
||||||
_ObjectDebugLock(Object *p_obj) {
|
_ObjectDebugLock(Object *p_obj) {
|
||||||
obj = p_obj;
|
obj_id = p_obj->get_instance_id();
|
||||||
obj->_lock_index.ref();
|
p_obj->_lock_index.ref();
|
||||||
}
|
}
|
||||||
~_ObjectDebugLock() {
|
~_ObjectDebugLock() {
|
||||||
obj->_lock_index.unref();
|
Object *obj_ptr = ObjectDB::get_instance(obj_id);
|
||||||
|
if (likely(obj_ptr)) {
|
||||||
|
obj_ptr->_lock_index.unref();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue