Fix crash when casting from null

This commit is contained in:
Haoyu Qiu 2021-09-24 23:31:17 +08:00
parent 7893dd26df
commit 8a47fe9eb0

View file

@ -804,22 +804,15 @@ bool Variant::is_one() const {
} }
ObjectID Variant::get_object_instance_id() const { ObjectID Variant::get_object_instance_id() const {
if (type != OBJECT) { if (unlikely(type != OBJECT)) {
return 0; return 0;
} } else if (likely(_get_obj().rc)) {
#ifdef DEBUG_ENABLED
if (is_ref()) {
return !_get_obj().ref.is_null() ? _REF_OBJ_PTR(*this)->get_instance_id() : 0;
} else {
return _get_obj().rc->instance_id; return _get_obj().rc->instance_id;
} } else if (likely(!_get_obj().ref.is_null())) {
#else return _REF_OBJ_PTR(*this)->get_instance_id();
if (is_ref() && _get_obj().ref.is_null()) {
return 0;
} else { } else {
return _get_obj().rc->get_ptr()->get_instance_id(); return 0;
} }
#endif
} }
bool Variant::is_invalid_object() const { bool Variant::is_invalid_object() const {