Object::script may not be a valid Ref<Script>

It appears that Object::script may be a valid ScriptInstance but not be
castable to Ref<Script>. There were only 5 places in the code that made
this assumption. This commit fixes that.

(cherry picked from commit 20b0046945)
This commit is contained in:
Hein-Pieter van Braam-Stewart 2019-04-19 22:03:00 +02:00 committed by Rémi Verschelde
parent 733668074a
commit 0b4dec63a9
3 changed files with 23 additions and 14 deletions

View File

@ -1330,7 +1330,10 @@ Array Object::_get_incoming_connections() const {
void Object::get_signal_list(List<MethodInfo> *p_signals) const {
if (!script.is_null()) {
Ref<Script>(script)->get_script_signal_list(p_signals);
Ref<Script> scr = script;
if (scr.is_valid()) {
scr->get_script_signal_list(p_signals);
}
}
ClassDB::get_signal_list(get_class_name(), p_signals);

View File

@ -2397,6 +2397,7 @@ void PropertyEditor::_check_reload_status(const String &p_name, TreeItem *item)
if (!has_reload && !obj->get_script().is_null()) {
Ref<Script> scr = obj->get_script();
if (scr.is_valid()) {
Variant orig_value;
if (scr->get_property_default_value(p_name, orig_value)) {
if (orig_value != obj->get(p_name)) {
@ -2404,6 +2405,7 @@ void PropertyEditor::_check_reload_status(const String &p_name, TreeItem *item)
}
}
}
}
if (found != -1 && !has_reload) {
@ -3558,6 +3560,7 @@ void PropertyEditor::update_tree() {
if (!has_reload && !obj->get_script().is_null()) {
Ref<Script> scr = obj->get_script();
if (scr.is_valid()) {
Variant orig_value;
if (scr->get_property_default_value(p.name, orig_value)) {
if (orig_value != obj->get(p.name)) {
@ -3566,6 +3569,7 @@ void PropertyEditor::update_tree() {
}
}
}
}
if (_might_be_in_instance() && !has_reload && item->get_cell_mode(1) == TreeItem::CELL_MODE_RANGE && item->get_text(1) == String()) {
item->add_button(1, get_icon("ReloadEmpty", "EditorIcons"), 3, true);
@ -3950,11 +3954,13 @@ void PropertyEditor::_edit_button(Object *p_item, int p_column, int p_button) {
if (!obj->get_script().is_null()) {
Ref<Script> scr = obj->get_script();
if (scr.is_valid()) {
Variant orig_value;
if (scr->get_property_default_value(prop, orig_value)) {
_edit_set(prop, orig_value);
}
}
}
} else {

View File

@ -2560,7 +2560,7 @@ void Node::_replace_connections_target(Node *p_new_target) {
if (c.flags & CONNECT_PERSIST) {
c.source->disconnect(c.signal, this, c.method);
bool valid = p_new_target->has_method(c.method) || p_new_target->get_script().is_null() || Ref<Script>(p_new_target->get_script())->has_method(c.method);
bool valid = p_new_target->has_method(c.method) || Ref<Script>(p_new_target->get_script()).is_null() || Ref<Script>(p_new_target->get_script())->has_method(c.method);
ERR_EXPLAIN("Attempt to connect signal \'" + c.source->get_class() + "." + c.signal + "\' to nonexistent method \'" + c.target->get_class() + "." + c.method + "\'");
ERR_CONTINUE(!valid);
c.source->connect(c.signal, p_new_target, c.method, c.binds, c.flags);