From 704a842aed45491d0939f021ef74d1239c29f895 Mon Sep 17 00:00:00 2001 From: Kawe Mazidjatari <48657826+Mauler125@users.noreply.github.com> Date: Sat, 28 Dec 2024 20:32:45 +0100 Subject: [PATCH] Fix crash when MSW shader entry is nullptr The shader entry can be a null if its simply not used by the game, or if it is a reference. We must correctly check on these correctly to avoid the program from crashing. Repak now adds these kinds of shaders correctly to the pak file. --- src/assets/shader.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/assets/shader.cpp b/src/assets/shader.cpp index 5407567..171cdf2 100644 --- a/src/assets/shader.cpp +++ b/src/assets/shader.cpp @@ -19,8 +19,8 @@ static void Shader_CreateFromMSW(CPakFileBuilder* const pak, PakPageLump_s& cpuD for (auto& it : shader->entries) { - if (it.buffer != nullptr) - totalShaderDataSize += IALIGN(it.size, 8); + if (it.buffer == nullptr) + continue; // If the shader type hasn't been found yet, parse this buffer and find out what we want to set it as. if (hdr->type == eShaderType::Invalid) @@ -33,6 +33,8 @@ static void Shader_CreateFromMSW(CPakFileBuilder* const pak, PakPageLump_s& cpuD } } } + + totalShaderDataSize += IALIGN(it.size, 8); } assert(totalShaderDataSize != 0);