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 2 commits 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.
9d50a58 to
a12e5df
Compare
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
a12e5df to
57a0110
Compare
There was a problem hiding this comment.
🟡 Changes recommended
The new DFF-texture unwatch logic relies on raw STexInfo* pointer identity to prevent cross-talk on reused D3D keys, which can fail under allocator pointer reuse and lead to incorrect usage-counting/deletion.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Review details
- Files reviewed: 3/3 changed files
- Comments generated: 1
- Review effort level: Lite
The map is keyed on the D3D texture, and that address can be reused once it is released.
57a0110 to
d388a9e
Compare
There was a problem hiding this comment.
🔵 Needs a closer look
It modifies low-level RenderWare resource-lifetime tracking and adds new runtime hooks, which warrants final human verification across game/client build variants and teardown paths.
Review details
- Files reviewed: 3/3 changed files
- Comments generated: 0 new
- Review effort level: Lite
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