aboutsummaryrefslogtreecommitdiff
path: root/editor/io_plugins/editor_texture_import_plugin.cpp
diff options
context:
space:
mode:
authorHein-Pieter van Braam2017-08-24 22:58:51 +0200
committerHein-Pieter van Braam2017-08-24 23:08:24 +0200
commitcacced7e507f7603bacc03ae2616e58f0ede122a (patch)
tree7af89373e86cd1a7af6ea04e10280084cabb7144 /editor/io_plugins/editor_texture_import_plugin.cpp
parent4aa2c18cb428ffde05c67987926736a9ca62703b (diff)
downloadgodot-cacced7e507f7603bacc03ae2616e58f0ede122a.tar.gz
godot-cacced7e507f7603bacc03ae2616e58f0ede122a.tar.zst
godot-cacced7e507f7603bacc03ae2616e58f0ede122a.zip
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/io_plugins/editor_texture_import_plugin.cpp')
-rw-r--r--editor/io_plugins/editor_texture_import_plugin.cpp10
1 files changed, 5 insertions, 5 deletions
diff --git a/editor/io_plugins/editor_texture_import_plugin.cpp b/editor/io_plugins/editor_texture_import_plugin.cpp
index 1dc264147..943237764 100644
--- a/editor/io_plugins/editor_texture_import_plugin.cpp
+++ b/editor/io_plugins/editor_texture_import_plugin.cpp
@@ -703,7 +703,7 @@ EditorTextureImportDialog::EditorTextureImportDialog(EditorTextureImportPlugin*
VBoxContainer *source_vb=memnew(VBoxContainer);
MarginContainer *source_mc = vbc->add_margin_child(TTR("Source Texture(s):"),source_vb);
- source_label = vbc->get_child(source_mc->get_index()-1)->cast_to<Label>();
+ source_label = Object::cast_to<Label>(vbc->get_child(source_mc->get_index()-1));
HBoxContainer *hbc = memnew( HBoxContainer );
source_vb->add_child(hbc);
@@ -733,7 +733,7 @@ EditorTextureImportDialog::EditorTextureImportDialog(EditorTextureImportPlugin*
size->set_value(256);
size_mc=vbc->add_margin_child(TTR("Cell Size:"),size);
- size_label=vbc->get_child(size_mc->get_index()-1)->cast_to<Label>();
+ size_label=Object::cast_to<Label>(vbc->get_child(size_mc->get_index()-1));
save_path = memnew( LineEdit );
@@ -1326,7 +1326,7 @@ Error EditorTextureImportPlugin::import2(const String& p_path, const Ref<Resourc
if (ResourceCache::has(apath)) {
- at = Ref<AtlasTexture>( ResourceCache::get(apath)->cast_to<AtlasTexture>() );
+ at = Ref<AtlasTexture>( Object::cast_to<AtlasTexture>(ResourceCache::get(apath)) );
} else {
at = Ref<AtlasTexture>( memnew( AtlasTexture ) );
@@ -1340,7 +1340,7 @@ Error EditorTextureImportPlugin::import2(const String& p_path, const Ref<Resourc
}
}
if (ResourceCache::has(p_path)) {
- texture = Ref<ImageTexture> ( ResourceCache::get(p_path)->cast_to<ImageTexture>() );
+ texture = Ref<ImageTexture> ( Object::cast_to<ImageTexture>(ResourceCache::get(p_path)) );
} else {
texture = Ref<ImageTexture>( memnew( ImageTexture ) );
}
@@ -1354,7 +1354,7 @@ Error EditorTextureImportPlugin::import2(const String& p_path, const Ref<Resourc
if (ResourceCache::has(p_path)) {
Resource *r = ResourceCache::get(p_path);
- texture = Ref<ImageTexture> ( r->cast_to<ImageTexture>() );
+ texture = Ref<ImageTexture> ( Object::cast_to<ImageTexture>(r) );
Image img;
Error err = img.load(src_path);