Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GH-796 Guard against get_current_scene returning null #797

Merged
merged 1 commit into from
Sep 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/script/nodes/dialogue/dialogue_message.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include <godot_cpp/classes/packed_scene.hpp>
#include <godot_cpp/classes/resource_loader.hpp>
#include <godot_cpp/classes/scene_tree.hpp>
#include <godot_cpp/classes/window.hpp>

class OScriptNodeDialogueMessageInstance : public OScriptNodeInstance
{
Expand Down Expand Up @@ -105,6 +106,15 @@ class OScriptNodeDialogueMessageInstance : public OScriptNodeInstance
state->connect_to_signal(_ui, "show_message_finished", Array());

Node* root = node->get_tree()->get_current_scene();
if (!root)
root = node->get_tree()->get_root()->get_child(0);

if (!root)
{
p_context.set_error("Cannot find root node");
return -1 | STEP_FLAG_END;
}

if (!root->is_node_ready())
root->call_deferred("add_child", _ui);
else
Expand Down
3 changes: 2 additions & 1 deletion src/script/nodes/properties/property_get.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

#include <godot_cpp/classes/node.hpp>
#include <godot_cpp/classes/scene_tree.hpp>
#include <godot_cpp/classes/window.hpp>

class OScriptNodePropertyGetInstance : public OScriptNodeInstance
{
Expand All @@ -34,7 +35,7 @@ class OScriptNodePropertyGetInstance : public OScriptNodeInstance
Node* _get_node_path_target(OScriptExecutionContext& p_context)
{
if (Node* owner = Object::cast_to<Node>(p_context.get_owner()))
return owner->get_tree()->get_current_scene()->get_node_or_null(_node_path);
return owner->get_tree()->get_root()->get_node_or_null(_node_path);
return nullptr;
}

Expand Down
3 changes: 2 additions & 1 deletion src/script/nodes/properties/property_set.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

#include <godot_cpp/classes/node.hpp>
#include <godot_cpp/classes/scene_tree.hpp>
#include <godot_cpp/classes/window.hpp>

class OScriptNodePropertySetInstance : public OScriptNodeInstance
{
Expand All @@ -34,7 +35,7 @@ class OScriptNodePropertySetInstance : public OScriptNodeInstance
Node* _get_node_path_target(OScriptExecutionContext& p_context)
{
if (Node* owner = Object::cast_to<Node>(p_context.get_owner()))
return owner->get_tree()->get_current_scene()->get_node_or_null(_node_path);
return owner->get_tree()->get_root()->get_node_or_null(_node_path);
return nullptr;
}

Expand Down
42 changes: 24 additions & 18 deletions src/script/nodes/utilities/print_string.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,25 +92,31 @@ int OScriptNodePrintStringInstance::step(OScriptExecutionContext& p_context)
{
SceneTree* tree = _get_tree(p_context);

Node* container = _get_or_create_ui_container(tree->get_current_scene());
if (container)
Node* root = tree->get_current_scene();
if (!root)
root = tree->get_root()->get_child(0);

if (root)
{
Variant text = p_context.get_input(0);

RichTextLabel* label = memnew(RichTextLabel);
label->set_fit_content(true);
label->set_use_bbcode(true);
label->set_mouse_filter(Control::MOUSE_FILTER_IGNORE);
label->set_h_size_flags(Control::SIZE_EXPAND_FILL);
label->set_autowrap_mode(TextServer::AUTOWRAP_OFF);
container->add_child(label);

label->push_color(p_context.get_input(3));
label->append_text(text);
label->pop();

Ref<SceneTreeTimer> timer = tree->create_timer(p_context.get_input(4));
timer->connect("timeout", Callable(label, "queue_free"));
if (Node* container = _get_or_create_ui_container(root))
{
Variant text = p_context.get_input(0);

RichTextLabel* label = memnew(RichTextLabel);
label->set_fit_content(true);
label->set_use_bbcode(true);
label->set_mouse_filter(Control::MOUSE_FILTER_IGNORE);
label->set_h_size_flags(Control::SIZE_EXPAND_FILL);
label->set_autowrap_mode(TextServer::AUTOWRAP_OFF);
container->add_child(label);

label->push_color(p_context.get_input(3));
label->append_text(text);
label->pop();

Ref<SceneTreeTimer> timer = tree->create_timer(p_context.get_input(4));
timer->connect("timeout", Callable(label, "queue_free"));
}
}
}

Expand Down
Loading