summaryrefslogtreecommitdiffstats
path: root/modules/visual_script/visual_script_yield_nodes.cpp
diff options
context:
space:
mode:
authorHein-Pieter van Braam <hp@tmm.cx>2017-08-24 22:58:51 +0200
committerHein-Pieter van Braam <hp@tmm.cx>2017-08-24 23:08:24 +0200
commitcacced7e507f7603bacc03ae2616e58f0ede122a (patch)
tree7af89373e86cd1a7af6ea04e10280084cabb7144 /modules/visual_script/visual_script_yield_nodes.cpp
parent4aa2c18cb428ffde05c67987926736a9ca62703b (diff)
downloadredot-engine-cacced7e507f7603bacc03ae2616e58f0ede122a.tar.gz
Convert Object::cast_to() to the static version
Currently we rely on some undefined behavior when Object->cast_to() gets called with a Null pointer. This used to work fine with GCC < 6 but newer versions of GCC remove all codepaths in which the this pointer is Null. However, the non-static cast_to() was supposed to be null safe. This patch makes cast_to() Null safe and removes the now redundant Null checks where they existed. It is explained in this article: https://www.viva64.com/en/b/0226/
Diffstat (limited to 'modules/visual_script/visual_script_yield_nodes.cpp')
-rw-r--r--modules/visual_script/visual_script_yield_nodes.cpp9
1 files changed, 3 insertions, 6 deletions
diff --git a/modules/visual_script/visual_script_yield_nodes.cpp b/modules/visual_script/visual_script_yield_nodes.cpp
index df88d2e7f7..958eacf2f2 100644
--- a/modules/visual_script/visual_script_yield_nodes.cpp
+++ b/modules/visual_script/visual_script_yield_nodes.cpp
@@ -105,7 +105,7 @@ public:
} else {
//yield
- SceneTree *tree = OS::get_singleton()->get_main_loop()->cast_to<SceneTree>();
+ SceneTree *tree = Object::cast_to<SceneTree>(OS::get_singleton()->get_main_loop());
if (!tree) {
r_error_str = "Main Loop is not SceneTree";
r_error.error = Variant::CallError::CALL_ERROR_INVALID_METHOD;
@@ -252,10 +252,7 @@ Node *VisualScriptYieldSignal::_get_base_node() const {
return NULL;
MainLoop *main_loop = OS::get_singleton()->get_main_loop();
- if (!main_loop)
- return NULL;
-
- SceneTree *scene_tree = main_loop->cast_to<SceneTree>();
+ SceneTree *scene_tree = Object::cast_to<SceneTree>(main_loop);
if (!scene_tree)
return NULL;
@@ -530,7 +527,7 @@ public:
} break;
case VisualScriptYieldSignal::CALL_MODE_NODE_PATH: {
- Node *node = instance->get_owner_ptr()->cast_to<Node>();
+ Node *node = Object::cast_to<Node>(instance->get_owner_ptr());
if (!node) {
r_error.error = Variant::CallError::CALL_ERROR_INVALID_METHOD;
r_error_str = "Base object is not a Node!";