Skip to content

Commit

Permalink
Make Variant aware that an Object may be a Reference
Browse files Browse the repository at this point in the history
  • Loading branch information
RandomShaper committed Oct 29, 2020
1 parent 798ee98 commit 1e9a774
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions core/variant.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2338,12 +2338,20 @@ Variant::Variant(const RID &p_rid) {
Variant::Variant(const Object *p_object) {

type = OBJECT;
Object *obj = const_cast<Object *>(p_object);

memnew_placement(_data._mem, ObjData);
Reference *ref = Object::cast_to<Reference>(obj);
if (unlikely(ref)) {
*reinterpret_cast<Ref<Reference> *>(_get_obj().ref.get_data()) = Ref<Reference>(ref);
#ifdef DEBUG_ENABLED
_get_obj().rc = p_object ? const_cast<Object *>(p_object)->_use_rc() : NULL;
#else
_get_obj().obj = const_cast<Object *>(p_object);
_get_obj().rc = NULL;
} else {
_get_obj().rc = likely(obj) ? obj->_use_rc() : NULL;
#endif
}
#if !defined(DEBUG_ENABLED)
_get_obj().obj = obj;
#endif
}

Expand Down

0 comments on commit 1e9a774

Please sign in to comment.