mirror of
https://github.com/godotengine/godot.git
synced 2025-10-20 00:13:30 +00:00
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/
This commit is contained in:
parent
4aa2c18cb4
commit
cacced7e50
185 changed files with 1314 additions and 1508 deletions
|
@ -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!";
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue