[GDNative] fix NativeScript leak in editor

This commit is contained in:
thomas.herzog 2019-03-22 12:54:19 +01:00
parent 0e5b2b16ed
commit 5fff7f741a
2 changed files with 18 additions and 21 deletions

View File

@ -160,8 +160,10 @@ bool NativeScript::can_instance() const {
NativeScriptDesc *script_data = get_script_desc(); NativeScriptDesc *script_data = get_script_desc();
#ifdef TOOLS_ENABLED #ifdef TOOLS_ENABLED
// Only valid if this is either a tool script or a "regular" script.
return script_data || (!is_tool() && !ScriptServer::is_scripting_enabled()); // (so an environment whre scripting is disabled (and not the editor) would not
// create objects).
return script_data && (is_tool() || ScriptServer::is_scripting_enabled());
#else #else
return script_data; return script_data;
#endif #endif
@ -199,25 +201,6 @@ ScriptInstance *NativeScript::instance_create(Object *p_this) {
return NULL; return NULL;
} }
#ifdef TOOLS_ENABLED
if (!ScriptServer::is_scripting_enabled() && !is_tool()) {
// placeholder for nodes. For tools we want the rool thing.
PlaceHolderScriptInstance *sins = memnew(PlaceHolderScriptInstance(NSL, Ref<Script>(this), p_this));
placeholders.insert(sins);
if (script_data->create_func.create_func) {
script_data->create_func.create_func(
(godot_object *)p_this,
script_data->create_func.method_data);
}
_update_placeholder(sins);
return sins;
}
#endif
NativeScriptInstance *nsi = memnew(NativeScriptInstance); NativeScriptInstance *nsi = memnew(NativeScriptInstance);
nsi->owner = p_this; nsi->owner = p_this;
@ -246,6 +229,19 @@ ScriptInstance *NativeScript::instance_create(Object *p_this) {
return nsi; return nsi;
} }
PlaceHolderScriptInstance *NativeScript::placeholder_instance_create(Object *p_this) {
#ifdef TOOLS_ENABLED
PlaceHolderScriptInstance *sins = memnew(PlaceHolderScriptInstance(NSL, Ref<Script>(this), p_this));
placeholders.insert(sins);
_update_placeholder(sins);
return sins;
#else
return NULL;
#endif
}
bool NativeScript::instance_has(const Object *p_this) const { bool NativeScript::instance_has(const Object *p_this) const {
return instance_owners.has((Object *)p_this); return instance_owners.has((Object *)p_this);
} }

View File

@ -149,6 +149,7 @@ public:
virtual StringName get_instance_base_type() const; // this may not work in all scripts, will return empty if so virtual StringName get_instance_base_type() const; // this may not work in all scripts, will return empty if so
virtual ScriptInstance *instance_create(Object *p_this); virtual ScriptInstance *instance_create(Object *p_this);
virtual PlaceHolderScriptInstance *placeholder_instance_create(Object *p_this);
virtual bool instance_has(const Object *p_this) const; virtual bool instance_has(const Object *p_this) const;
virtual bool has_source_code() const; virtual bool has_source_code() const;