Skip to content

Commit

Permalink
Merge pull request #43049 from RandomShaper/fix_gone_script_3.2
Browse files Browse the repository at this point in the history
Fix script used as type gone too early (3.2)
  • Loading branch information
akien-mga authored Oct 30, 2020
2 parents e6d0770 + 1e9a774 commit 82bc682
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 13 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
1 change: 0 additions & 1 deletion modules/gdscript/gdscript.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -914,7 +914,6 @@ void GDScript::get_script_signal_list(List<MethodInfo> *r_signals) const {
GDScript::GDScript() :
script_list(this) {

_static_ref = this;
valid = false;
subclass_count = 0;
initializer = NULL;
Expand Down
1 change: 0 additions & 1 deletion modules/gdscript/gdscript.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ class GDScript : public Script {
friend class GDScriptFunctions;
friend class GDScriptLanguage;

Variant _static_ref; //used for static call
Ref<GDScriptNativeClass> native;
Ref<GDScript> base;
GDScript *_base; //fast pointer access
Expand Down
17 changes: 10 additions & 7 deletions modules/gdscript/gdscript_function.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
#include "gdscript.h"
#include "gdscript_functions.h"

Variant *GDScriptFunction::_get_variant(int p_address, GDScriptInstance *p_instance, GDScript *p_script, Variant &self, Variant *p_stack, String &r_error) const {
Variant *GDScriptFunction::_get_variant(int p_address, GDScriptInstance *p_instance, GDScript *p_script, Variant &self, Variant &static_ref, Variant *p_stack, String &r_error) const {

int address = p_address & ADDR_MASK;

Expand All @@ -52,7 +52,7 @@ Variant *GDScriptFunction::_get_variant(int p_address, GDScriptInstance *p_insta
} break;
case ADDR_TYPE_CLASS: {

return &p_script->_static_ref;
return &static_ref;
} break;
case ADDR_TYPE_MEMBER: {
#ifdef DEBUG_ENABLED
Expand Down Expand Up @@ -269,6 +269,7 @@ Variant GDScriptFunction::call(GDScriptInstance *p_instance, const Variant **p_a
r_err.error = Variant::CallError::CALL_OK;

Variant self;
Variant static_ref;
Variant retvalue;
Variant *stack = NULL;
Variant **call_args;
Expand Down Expand Up @@ -385,6 +386,8 @@ Variant GDScriptFunction::call(GDScriptInstance *p_instance, const Variant **p_a
}
}

static_ref = script;

String err_text;

#ifdef DEBUG_ENABLED
Expand All @@ -403,18 +406,18 @@ Variant GDScriptFunction::call(GDScriptInstance *p_instance, const Variant **p_a
#define CHECK_SPACE(m_space) \
GD_ERR_BREAK((ip + m_space) > _code_size)

#define GET_VARIANT_PTR(m_v, m_code_ofs) \
Variant *m_v; \
m_v = _get_variant(_code_ptr[ip + m_code_ofs], p_instance, script, self, stack, err_text); \
if (unlikely(!m_v)) \
#define GET_VARIANT_PTR(m_v, m_code_ofs) \
Variant *m_v; \
m_v = _get_variant(_code_ptr[ip + m_code_ofs], p_instance, script, self, static_ref, stack, err_text); \
if (unlikely(!m_v)) \
OPCODE_BREAK;

#else
#define GD_ERR_BREAK(m_cond)
#define CHECK_SPACE(m_space)
#define GET_VARIANT_PTR(m_v, m_code_ofs) \
Variant *m_v; \
m_v = _get_variant(_code_ptr[ip + m_code_ofs], p_instance, script, self, stack, err_text);
m_v = _get_variant(_code_ptr[ip + m_code_ofs], p_instance, script, self, static_ref, stack, err_text);

#endif

Expand Down
2 changes: 1 addition & 1 deletion modules/gdscript/gdscript_function.h
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ class GDScriptFunction {

List<StackDebug> stack_debug;

_FORCE_INLINE_ Variant *_get_variant(int p_address, GDScriptInstance *p_instance, GDScript *p_script, Variant &self, Variant *p_stack, String &r_error) const;
_FORCE_INLINE_ Variant *_get_variant(int p_address, GDScriptInstance *p_instance, GDScript *p_script, Variant &self, Variant &static_ref, Variant *p_stack, String &r_error) const;
_FORCE_INLINE_ String _get_call_error(const Variant::CallError &p_err, const String &p_where, const Variant **argptrs) const;

friend class GDScriptLanguage;
Expand Down

0 comments on commit 82bc682

Please sign in to comment.