summaryrefslogtreecommitdiff
path: root/editor/plugins/texture_editor_plugin.cpp
diff options
context:
space:
mode:
authorHein-Pieter van Braam <hp@tmm.cx>2017-08-24 22:58:51 +0200
committerHein-Pieter van Braam <hp@tmm.cx>2017-08-24 23:08:24 +0200
commitcacced7e507f7603bacc03ae2616e58f0ede122a (patch)
tree7af89373e86cd1a7af6ea04e10280084cabb7144 /editor/plugins/texture_editor_plugin.cpp
parent4aa2c18cb428ffde05c67987926736a9ca62703b (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/texture_editor_plugin.cpp')
-rw-r--r--editor/plugins/texture_editor_plugin.cpp12
1 files changed, 6 insertions, 6 deletions
diff --git a/editor/plugins/texture_editor_plugin.cpp b/editor/plugins/texture_editor_plugin.cpp
index 57c27a8a7e..5648ee510e 100644
--- a/editor/plugins/texture_editor_plugin.cpp
+++ b/editor/plugins/texture_editor_plugin.cpp
@@ -70,7 +70,7 @@ void TextureEditor::_notification(int p_what) {
int ofs_x = (size.width - tex_width) / 2;
int ofs_y = (size.height - tex_height) / 2;
- if (texture->cast_to<CurveTexture>()) {
+ if (Object::cast_to<CurveTexture>(*texture)) {
// In the case of CurveTextures we know they are 1 in height, so fill the preview to see the gradient
ofs_y = 0;
tex_height = size.height;
@@ -81,10 +81,10 @@ void TextureEditor::_notification(int p_what) {
Ref<Font> font = get_font("font", "Label");
String format;
- if (texture->cast_to<ImageTexture>()) {
- format = Image::get_format_name(texture->cast_to<ImageTexture>()->get_format());
- } else if (texture->cast_to<StreamTexture>()) {
- format = Image::get_format_name(texture->cast_to<StreamTexture>()->get_format());
+ if (Object::cast_to<ImageTexture>(*texture)) {
+ format = Image::get_format_name(Object::cast_to<ImageTexture>(*texture)->get_format());
+ } else if (Object::cast_to<StreamTexture>(*texture)) {
+ format = Image::get_format_name(Object::cast_to<StreamTexture>(*texture)->get_format());
} else {
format = texture->get_class();
}
@@ -136,7 +136,7 @@ TextureEditor::TextureEditor() {
void TextureEditorPlugin::edit(Object *p_object) {
- Texture *s = p_object->cast_to<Texture>();
+ Texture *s = Object::cast_to<Texture>(p_object);
if (!s)
return;