Skip to content

Commit 203f742

Browse files
committed
Fix crash when creating thumbnails for 3d textures
1 parent 4c4e673 commit 203f742

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

editor/plugins/editor_preview_plugins.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,9 +112,13 @@ Ref<Texture2D> EditorTexturePreviewPlugin::generate(const Ref<Resource> &p_from,
112112
return Ref<Texture2D>();
113113
}
114114

115-
const int mid_depth = (tex_3d->get_depth() - 1) / 2;
116-
117115
Vector<Ref<Image>> data = tex_3d->get_data();
116+
if (data.size() != tex_3d->get_depth()) {
117+
return Ref<Texture2D>();
118+
}
119+
120+
// Use the middle slice for the thumbnail.
121+
const int mid_depth = (tex_3d->get_depth() - 1) / 2;
118122
if (!data.is_empty() && data[mid_depth].is_valid()) {
119123
img = data[mid_depth]->duplicate();
120124
}
@@ -124,6 +128,7 @@ Ref<Texture2D> EditorTexturePreviewPlugin::generate(const Ref<Resource> &p_from,
124128
return Ref<Texture2D>();
125129
}
126130

131+
// Use the middle slice for the thumbnail.
127132
const int mid_layer = (tex_lyr->get_layers() - 1) / 2;
128133

129134
Ref<Image> data = tex_lyr->get_layer_data(mid_layer);

0 commit comments

Comments
 (0)