diff options
author | Hein-Pieter van Braam <hp@tmm.cx> | 2017-08-24 22:58:51 +0200 |
---|---|---|
committer | Hein-Pieter van Braam <hp@tmm.cx> | 2017-08-24 23:08:24 +0200 |
commit | cacced7e507f7603bacc03ae2616e58f0ede122a (patch) | |
tree | 7af89373e86cd1a7af6ea04e10280084cabb7144 /editor/plugins/shader_graph_editor_plugin.cpp | |
parent | 4aa2c18cb428ffde05c67987926736a9ca62703b (diff) |
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 'editor/plugins/shader_graph_editor_plugin.cpp')
-rw-r--r-- | editor/plugins/shader_graph_editor_plugin.cpp | 34 |
1 files changed, 17 insertions, 17 deletions
diff --git a/editor/plugins/shader_graph_editor_plugin.cpp b/editor/plugins/shader_graph_editor_plugin.cpp index 5506c035ec..7ad32464af 100644 --- a/editor/plugins/shader_graph_editor_plugin.cpp +++ b/editor/plugins/shader_graph_editor_plugin.cpp @@ -839,7 +839,7 @@ void ShaderGraphView::_vec_input_changed(double p_value, int p_id,Array p_arr){ void ShaderGraphView::_xform_input_changed(int p_id, Node *p_button){ - ToolButton *tb = p_button->cast_to<ToolButton>(); + ToolButton *tb = Object::cast_to<ToolButton>(p_button); ped_popup->set_position(tb->get_global_position()+Vector2(0,tb->get_size().height)); ped_popup->set_size(tb->get_size()); edited_id=p_id; @@ -850,7 +850,7 @@ void ShaderGraphView::_xform_input_changed(int p_id, Node *p_button){ } void ShaderGraphView::_xform_const_changed(int p_id, Node *p_button){ - ToolButton *tb = p_button->cast_to<ToolButton>(); + ToolButton *tb = Object::cast_to<ToolButton>(p_button); ped_popup->set_position(tb->get_global_position()+Vector2(0,tb->get_size().height)); ped_popup->set_size(tb->get_size()); edited_id=p_id; @@ -964,7 +964,7 @@ void ShaderGraphView::_variant_edited() { void ShaderGraphView::_comment_edited(int p_id,Node* p_button) { UndoRedo *ur=EditorNode::get_singleton()->get_undo_redo(); - TextEdit *te=p_button->cast_to<TextEdit>(); + TextEdit *te=Object::cast_to<TextEdit>(p_button); ur->create_action(TTR("Change Comment"),UndoRedo::MERGE_ENDS); ur->add_do_method(graph.ptr(),"comment_node_set_text",type,p_id,te->get_text()); ur->add_undo_method(graph.ptr(),"comment_node_set_text",type,p_id,graph->comment_node_get_text(type,p_id)); @@ -978,7 +978,7 @@ void ShaderGraphView::_comment_edited(int p_id,Node* p_button) { void ShaderGraphView::_color_ramp_changed(int p_id,Node* p_ramp) { - GraphColorRampEdit *cr=p_ramp->cast_to<GraphColorRampEdit>(); + GraphColorRampEdit *cr=Object::cast_to<GraphColorRampEdit>(p_ramp); UndoRedo *ur=EditorNode::get_singleton()->get_undo_redo(); @@ -1020,7 +1020,7 @@ void ShaderGraphView::_color_ramp_changed(int p_id,Node* p_ramp) { void ShaderGraphView::_curve_changed(int p_id,Node* p_curve) { - GraphCurveMapEdit *cr=p_curve->cast_to<GraphCurveMapEdit>(); + GraphCurveMapEdit *cr=Object::cast_to<GraphCurveMapEdit>(p_curve); UndoRedo *ur=EditorNode::get_singleton()->get_undo_redo(); @@ -1057,7 +1057,7 @@ void ShaderGraphView::_curve_changed(int p_id,Node* p_curve) { void ShaderGraphView::_input_name_changed(const String& p_name, int p_id, Node *p_line_edit) { - LineEdit *le=p_line_edit->cast_to<LineEdit>(); + LineEdit *le=Object::cast_to<LineEdit>(p_line_edit); ERR_FAIL_COND(!le); UndoRedo *ur=EditorNode::get_singleton()->get_undo_redo(); @@ -1074,7 +1074,7 @@ void ShaderGraphView::_input_name_changed(const String& p_name, int p_id, Node * void ShaderGraphView::_tex_edited(int p_id,Node* p_button) { - ToolButton *tb = p_button->cast_to<ToolButton>(); + ToolButton *tb = Object::cast_to<ToolButton>(p_button); ped_popup->set_position(tb->get_global_position()+Vector2(0,tb->get_size().height)); ped_popup->set_size(tb->get_size()); edited_id=p_id; @@ -1084,7 +1084,7 @@ void ShaderGraphView::_tex_edited(int p_id,Node* p_button) { void ShaderGraphView::_cube_edited(int p_id,Node* p_button) { - ToolButton *tb = p_button->cast_to<ToolButton>(); + ToolButton *tb = Object::cast_to<ToolButton>(p_button); ped_popup->set_position(tb->get_global_position()+Vector2(0,tb->get_size().height)); ped_popup->set_size(tb->get_size()); edited_id=p_id; @@ -1299,7 +1299,7 @@ void ShaderGraphView::_delete_nodes_request() void ShaderGraphView::_default_changed(int p_id, Node *p_button, int p_param, int v_type, String p_hint) { - ToolButton *tb = p_button->cast_to<ToolButton>(); + ToolButton *tb = Object::cast_to<ToolButton>(p_button); ped_popup->set_position(tb->get_global_position()+Vector2(0,tb->get_size().height)); ped_popup->set_size(tb->get_size()); edited_id=p_id; @@ -2530,7 +2530,7 @@ void ShaderGraphView::_sg_updated() { Variant ShaderGraphView::get_drag_data_fw(const Point2 &p_point, Control *p_from) { - TextureRect* frame = p_from->cast_to<TextureRect>(); + TextureRect* frame = Object::cast_to<TextureRect>(p_from); if (!frame) return Variant(); @@ -2556,7 +2556,7 @@ bool ShaderGraphView::can_drop_data_fw(const Point2 &p_point, const Variant &p_d if (val.get_type()==Variant::OBJECT) { RES res = val; - if (res.is_valid() && res->cast_to<Texture>()) + if (res.is_valid() && Object::cast_to<Texture>(res)) return true; } } @@ -2576,7 +2576,7 @@ void ShaderGraphView::drop_data_fw(const Point2 &p_point, const Variant &p_data, if (!can_drop_data_fw(p_point, p_data, p_from)) return; - TextureRect *frame = p_from->cast_to<TextureRect>(); + TextureRect *frame = Object::cast_to<TextureRect>(p_from); if (!frame) return; @@ -2590,20 +2590,20 @@ void ShaderGraphView::drop_data_fw(const Point2 &p_point, const Variant &p_data, if (val.get_type()==Variant::OBJECT) { RES res = val; if (res.is_valid()) - tex = Ref<Texture>(res->cast_to<Texture>()); + tex = Ref<Texture>(Object::cast_to<Texture>(*res)); } } else if (d["type"] == "files" && d.has("files")) { Vector<String> files = d["files"]; RES res = ResourceLoader::load(files[0]); if (res.is_valid()) - tex = Ref<Texture>(res->cast_to<Texture>()); + tex = Ref<Texture>(Object::cast_to<Texture>(*res)); } } if (!tex.is_valid()) return; - GraphNode *gn = frame->get_parent()->cast_to<GraphNode>(); + GraphNode *gn = Object::cast_to<GraphNode>(frame->get_parent()); if (!gn) return; int id = -1; @@ -2896,12 +2896,12 @@ ShaderGraphEditor::ShaderGraphEditor(bool p_2d) { void ShaderGraphEditorPlugin::edit(Object *p_object) { - shader_editor->edit(p_object->cast_to<ShaderGraph>()); + shader_editor->edit(Object::cast_to<ShaderGraph>(p_object)); } bool ShaderGraphEditorPlugin::handles(Object *p_object) const { - ShaderGraph *shader=p_object->cast_to<ShaderGraph>(); + ShaderGraph *shader=Object::cast_to<ShaderGraph>(p_object); if (!shader) return false; if (_2d) |