From c3a11d760ecd41a8518c11c546f385a8c94d01c3 Mon Sep 17 00:00:00 2001 From: Lyuu17 Date: Fri, 28 Jun 2024 16:08:59 +0200 Subject: [PATCH] Check if sky texture exists before accessing it --- src/SWBF2/Level.cpp | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/SWBF2/Level.cpp b/src/SWBF2/Level.cpp index 264ac8a..5a2467e 100644 --- a/src/SWBF2/Level.cpp +++ b/src/SWBF2/Level.cpp @@ -152,11 +152,16 @@ namespace SWBF2 { godot::Sky *sky = memnew(godot::Sky); { - auto &texture = Native::SWBF2::m_tex[Native::SWBF2::m_skyDome.m_texture].m_formats[0].m_faceLevels[0].m_gdTexture; - godot::ProceduralSkyMaterial *procSkyMaterial = memnew(godot::ProceduralSkyMaterial); - procSkyMaterial->set_sky_cover(texture); + const auto &textureName = Native::SWBF2::m_skyDome.m_texture; - sky->set_material(procSkyMaterial); + if (Native::SWBF2::m_tex.contains(textureName)) + { + auto &texture = Native::SWBF2::m_tex[textureName].m_formats[0].m_faceLevels[0].m_gdTexture; + godot::ProceduralSkyMaterial *procSkyMaterial = memnew(godot::ProceduralSkyMaterial); + procSkyMaterial->set_sky_cover(texture); + + sky->set_material(procSkyMaterial); + } } env->set_background(godot::Environment::BG_SKY);