From cacced7e507f7603bacc03ae2616e58f0ede122a Mon Sep 17 00:00:00 2001 From: Hein-Pieter van Braam Date: Thu, 24 Aug 2017 22:58:51 +0200 Subject: 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/ --- editor/plugins/baked_light_baker.cpp | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) (limited to 'editor/plugins/baked_light_baker.cpp') diff --git a/editor/plugins/baked_light_baker.cpp b/editor/plugins/baked_light_baker.cpp index bef35647d..d76bdad85 100644 --- a/editor/plugins/baked_light_baker.cpp +++ b/editor/plugins/baked_light_baker.cpp @@ -301,16 +301,13 @@ void BakedLightBaker::_add_mesh(const Ref& p_mesh,const Ref& p_m void BakedLightBaker::_parse_geometry(Node* p_node) { - if (p_node->cast_to()) { + if (MeshInstance *meshi=Object::cast_to(p_node)) { - MeshInstance *meshi=p_node->cast_to(); Ref mesh=meshi->get_mesh(); if (mesh.is_valid()) { _add_mesh(mesh,meshi->get_material_override(),base_inv * meshi->get_global_transform(),meshi->get_baked_light_texture_id()); } - } else if (p_node->cast_to()) { - - Light *dl=p_node->cast_to(); + } else if (Light *dl=Object::cast_to(p_node)) { if (dl->get_bake_mode()!=Light::BAKE_MODE_DISABLED) { @@ -340,9 +337,7 @@ void BakedLightBaker::_parse_geometry(Node* p_node) { lights.push_back(dirl); } - } else if (p_node->cast_to()){ - - Spatial *sp = p_node->cast_to(); + } else if (Spatial *sp = Object::cast_to(p_node)){ Array arr = p_node->call("_get_baked_light_meshes"); for(int i=0;i &p_light, Node* p_node) { return; cell_count=0; - base_inv=p_node->cast_to()->get_global_transform().affine_inverse(); + base_inv=Object::cast_to(p_node)->get_global_transform().affine_inverse(); EditorProgress ep("bake",TTR("Light Baker Setup:"),5); baked_light=p_light; lattice_size=baked_light->get_initial_lattice_subdiv(); -- cgit v1.2.3-70-g09d2