Skip to content

Commit

Permalink
Fix crash when creating thumbnails for 3d textures
Browse files Browse the repository at this point in the history
  • Loading branch information
BlueCube3310 committed Oct 9, 2024
1 parent 4c4e673 commit 203f742
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions editor/plugins/editor_preview_plugins.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand All @@ -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);
Expand Down

0 comments on commit 203f742

Please sign in to comment.