1
0
mirror of https://github.com/godotengine/godot.git synced 2025-11-05 12:10:55 +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:
Hein-Pieter van Braam
2017-08-24 22:58:51 +02:00
parent 4aa2c18cb4
commit cacced7e50
185 changed files with 1314 additions and 1508 deletions

View File

@@ -1329,7 +1329,7 @@ void TileMapEditor::edit(Node *p_tile_map) {
node->disconnect("settings_changed", this, "_tileset_settings_changed");
if (p_tile_map) {
node = p_tile_map->cast_to<TileMap>();
node = Object::cast_to<TileMap>(p_tile_map);
if (!canvas_item_editor->is_connected("draw", this, "_canvas_draw"))
canvas_item_editor->connect("draw", this, "_canvas_draw");
if (!canvas_item_editor->is_connected("mouse_entered", this, "_canvas_mouse_enter"))
@@ -1407,7 +1407,7 @@ TileMapEditor::CellOp TileMapEditor::_get_op_from_cell(const Point2i &p_pos) {
void TileMapEditor::_update_transform_buttons(Object *p_button) {
//ERR_FAIL_NULL(p_button);
ToolButton *b = p_button->cast_to<ToolButton>();
ToolButton *b = Object::cast_to<ToolButton>(p_button);
//ERR_FAIL_COND(!b);
if (b == rotate_0) {
@@ -1582,7 +1582,7 @@ TileMapEditor::~TileMapEditor() {
void TileMapEditorPlugin::edit(Object *p_object) {
tile_map_editor->edit(p_object->cast_to<Node>());
tile_map_editor->edit(Object::cast_to<Node>(p_object));
}
bool TileMapEditorPlugin::handles(Object *p_object) const {