From bbc08986d48f1c6dd88022a06f4c5ca2e651876d Mon Sep 17 00:00:00 2001 From: salmonik Date: Wed, 4 Nov 2026 00:43:49 +0100 Subject: Skybox image: drop Refresh/SetUndefined (crash after apply) The last crash happened after "applied", in materialsystem while the renderer walked a shader-parameter list that contained a null vtable entry. That points at the Refresh()/SetUndefined experiment: undefining $hdrcompressedtexture while the sky shader's static combo still expected it (and rebuilding state mid-level) left a broken material. Set the texture on $basetexture/$hdrbasetexture/$hdrcompressedtexture (and the 0/1/2 variants) and do neither SetUndefined nor Refresh: the visible-path material binds its base texture dynamically, which is what made the earlier black sky (empty 798x798 VTF) appear black at all. Log the first sky material's shader name so we know whether this map uses the LDR (UnlitGeneric) or HDR (sky) path. --- src/world.cpp | 33 +++++++++++---------------------- 1 file changed, 11 insertions(+), 22 deletions(-) (limited to 'src/world.cpp') diff --git a/src/world.cpp b/src/world.cpp index 1228c7a..eac31d9 100644 --- a/src/world.cpp +++ b/src/world.cpp @@ -741,10 +741,12 @@ int apply_sky_texture() { auto find_var = vfunc(mat, 11); // IMaterial::FindVar using GetTexFn = void *(*)(void *); - using IsDefFn = bool (*)(void *); - using UndefFn = void (*)(void *); + using ShaderFn = const char *(*)(void *); static const char *tex_vars[] = {"$basetexture", "$hdrbasetexture", - nullptr}; + "$hdrcompressedtexture", + "$hdrcompressedtexture0", + "$hdrcompressedtexture1", + "$hdrcompressedtexture2", nullptr}; for (int vi = 0; tex_vars[vi]; vi++) { bool found = false; void *var = find_var(mat, tex_vars[vi], &found, false); @@ -758,26 +760,13 @@ int apply_sky_texture() { if (vi == 0) hits++; } - // The HDR sky shader samples $hdrcompressedtexture (DXT5) when defined, - // which cannot hold our RGBA texture. Undefine it so the shader falls back - // to $hdrbasetexture, which now points at our image. - static const char *undef_vars[] = { - "$hdrcompressedtexture", "$hdrcompressedtexture0", - "$hdrcompressedtexture1", "$hdrcompressedtexture2", nullptr}; - for (int vi = 0; undef_vars[vi]; vi++) { - bool found = false; - void *var = find_var(mat, undef_vars[vi], &found, false); - if (!found || !var) - continue; - if (!vfunc(var, 17)(var)) - continue; - record_orig(name, undef_vars[vi], vfunc(var, 6)(var), - vfunc(var, 0)(var)); - vfunc(var, 18)(var); // SetUndefined + static bool logged_shader = false; + if (!logged_shader) { + logged_shader = true; + const char *shader = vfunc(mat, 49)(mat); // GetShaderName + logf("skybox: first sky material \"%s\" shader \"%s\"", name, + shader ? shader : "?"); } - // The sky shader binds its texture in SHADER_INIT, so changing the vars is - // not enough: rebuild the material's shader state. - vfunc(mat, 37)(mat); // IMaterial::Refresh } return hits; } -- cgit v1.2.3