Fix glTF scene export crash on null normal texture

Also removes a redundant get_texture call directly below
the modified code block.

Fixes #56379
This commit is contained in:
RedMser 2021-12-31 17:43:15 +01:00
parent 91b97dac03
commit 0e36d5e782

View file

@ -3402,8 +3402,10 @@ Error GLTFDocument::_serialize_materials(Ref<GLTFState> state) {
tex.instantiate();
{
Ref<Texture2D> normal_texture = material->get_texture(BaseMaterial3D::TEXTURE_NORMAL);
if (normal_texture.is_valid()) {
// Code for uncompressing RG normal maps
Ref<Image> img = normal_texture->get_image();
if (img.is_valid()) {
Ref<ImageTexture> img_tex = img;
if (img_tex.is_valid()) {
img = img_tex->get_image();
@ -3424,7 +3426,8 @@ Error GLTFDocument::_serialize_materials(Ref<GLTFState> state) {
}
tex->create_from_image(img);
}
Ref<Texture2D> normal_texture = material->get_texture(BaseMaterial3D::TEXTURE_NORMAL);
}
}
GLTFTextureIndex gltf_texture_index = -1;
if (tex.is_valid() && tex->get_image().is_valid()) {
tex->set_name(material->get_name() + "_normal");