summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBlueCube3310 <53150244+BlueCube3310@users.noreply.github.com>2024-10-08 17:56:17 +0200
committerBlueCube3310 <53150244+BlueCube3310@users.noreply.github.com>2024-10-09 12:34:19 +0200
commit203f7427c4952d3ba45a1dd89de019312a1f0bba (patch)
tree50ea002b2a571c9c61e6f66f427f241ffff3a864
parent4c4e67334412f73c9deba5e5d29afa8651418af2 (diff)
downloadredot-engine-203f7427c4952d3ba45a1dd89de019312a1f0bba.tar.gz
Fix crash when creating thumbnails for 3d textures
-rw-r--r--editor/plugins/editor_preview_plugins.cpp9
1 files changed, 7 insertions, 2 deletions
diff --git a/editor/plugins/editor_preview_plugins.cpp b/editor/plugins/editor_preview_plugins.cpp
index a2c36b1f3c..9a53f07a3f 100644
--- a/editor/plugins/editor_preview_plugins.cpp
+++ b/editor/plugins/editor_preview_plugins.cpp
@@ -112,9 +112,13 @@ Ref<Texture2D> EditorTexturePreviewPlugin::generate(const Ref<Resource> &p_from,
return Ref<Texture2D>();
}
- const int mid_depth = (tex_3d->get_depth() - 1) / 2;
-
Vector<Ref<Image>> data = tex_3d->get_data();
+ if (data.size() != tex_3d->get_depth()) {
+ return Ref<Texture2D>();
+ }
+
+ // Use the middle slice for the thumbnail.
+ const int mid_depth = (tex_3d->get_depth() - 1) / 2;
if (!data.is_empty() && data[mid_depth].is_valid()) {
img = data[mid_depth]->duplicate();
}
@@ -124,6 +128,7 @@ Ref<Texture2D> EditorTexturePreviewPlugin::generate(const Ref<Resource> &p_from,
return Ref<Texture2D>();
}
+ // Use the middle slice for the thumbnail.
const int mid_layer = (tex_lyr->get_layers() - 1) / 2;
Ref<Image> data = tex_lyr->get_layer_data(mid_layer);