diff --git a/modules/gltf/gltf_document.cpp b/modules/gltf/gltf_document.cpp index 572ef448766..9e7611bc5e1 100644 --- a/modules/gltf/gltf_document.cpp +++ b/modules/gltf/gltf_document.cpp @@ -3400,10 +3400,11 @@ Ref GLTFDocument::_get_texture(Ref p_state, const GLTFText const GLTFImageIndex image = p_state->textures[p_texture]->get_src_image(); ERR_FAIL_INDEX_V(image, p_state->images.size(), Ref()); if (GLTFState::GLTFHandleBinary(p_state->handle_binary_image) == GLTFState::GLTFHandleBinary::HANDLE_BINARY_EMBED_AS_BASISU) { + ERR_FAIL_INDEX_V(image, p_state->source_images.size(), Ref()); Ref portable_texture; portable_texture.instantiate(); portable_texture->set_keep_compressed_buffer(true); - Ref new_img = p_state->source_images[p_texture]->duplicate(); + Ref new_img = p_state->source_images[image]->duplicate(); ERR_FAIL_COND_V(new_img.is_null(), Ref()); new_img->generate_mipmaps(); if (p_texture_types) {