Fix shaders not working on replaced models after their txd unloads - #5305
Fix shaders not working on replaced models after their txd unloads#5305Flashmyname wants to merge 1 commit into
Conversation
There was a problem hiding this comment.
Pull request overview
Fixes a long-standing shader/texture-name lookup edge case for engineReplaceModel where a replaced model can keep rendering textures after their TXD streaming entry has been unloaded (making shaders stop applying and visible texture names disappear).
Changes:
- Track textures referenced by script-loaded DFF clumps (independent of TXD streaming) and stop tracking when the clump is destroyed.
- Add a fallback in shader lookup to consult the DFF-tracked texture map when the normal streamed texture lookup misses.
- Extend visible texture name lookup to include DFF-tracked textures.
Note for maintainers: when merging, please ensure the commit message(s) capture the goal/motivation (issues #3617/#4346), the approach (DFF texture watch map + render lookup fallback), and how you tested (the unload/reload and replace/restore cycle tests described in the PR).
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| Client/game_sa/CRenderWareSA.ShaderSupport.cpp | Adds DFF texture watch/unwatch and uses it as a fallback for shader application when streamed texinfo is missing. |
| Client/game_sa/CRenderWareSA.h | Introduces SDffTexInfo and a dedicated m_DffTexInfoMap, plus new helper declarations. |
| Client/game_sa/CRenderWareSA.cpp | Hooks DFF watch/unwatch into DFF lifetime, implements GetClumpTextures, and includes DFF map in GetTextureName. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
A replaced model keeps rendering textures whose txd streaming has unloaded, but the shader system has already dropped their texinfo, so shaders and engineGetVisibleTextureNames stop working for it. Watch a DFF's textures in their own map for as long as the clump uses them. Fixes multitheftauto#3617 Closes multitheftauto#4346
9d50a58 to
a12e5df
Compare
Summary
A model replaced with
engineReplaceModelkeeps rendering textures whose txd streaming has already unloaded. Their texinfo is gone by then, soengineApplyShaderToWorldTexturestops affecting the model andengineGetVisibleTextureNamesstops listing its textures, while it still looks correctly textured.Motivation
Fixes #3617. Closes #4346, a duplicate of it. Importing the txd first hides the bug, which is the difference #3617 describes.
Worth pairing with #5301, which removes the stale texinfos that sometimes mask this.
Test plan
Shader on
cedar2andplanta256, models 730 and 620 replaced with their gta3.img originals, then a forced txd unload and reload.shader_detail) went from 0 of 2355 samples without the fix to 1095 of 1095 with it.engineRestoreModel/engineReplaceModelcycles, no crash.Checklist