Skip to content

Fix shaders not working on replaced models after their txd unloads - #5305

Open
Flashmyname wants to merge 1 commit into
multitheftauto:masterfrom
Flashmyname:fix/4346-final
Open

Fix shaders not working on replaced models after their txd unloads#5305
Flashmyname wants to merge 1 commit into
multitheftauto:masterfrom
Flashmyname:fix/4346-final

Conversation

@Flashmyname

Copy link
Copy Markdown

Summary

A model replaced with engineReplaceModel keeps rendering textures whose txd streaming has already unloaded. Their texinfo is gone by then, so engineApplyShaderToWorldTexture stops affecting the model and engineGetVisibleTextureNames stops listing its textures, while it still looks correctly textured.

  • Watch a DFF's textures when it is read, stop when the clump is destroyed
  • Kept in their own map, so streaming and script texture removal cannot drop them
  • The render lookup only checks it when the existing one misses, so rendering is unchanged

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 cedar2 and planta256, models 730 and 620 replaced with their gta3.img originals, then a forced txd unload and reload.

  1. Model 730's textures were missing from the lookup in 95/95 samples before, present in 43/43 after.
  2. Model 620, whose txd stayed loaded, was unaffected either way.
  3. Shaders doesn't work on replaced models sometime #3617's own repro (13101 with shader_detail) went from 0 of 2355 samples without the fix to 1095 of 1095 with it.
  4. 60 engineRestoreModel / engineReplaceModel cycles, no crash.

Checklist

  • Your code should follow the coding guidelines.
  • Smaller pull requests are easier to review. If your pull request is beefy, your pull request should be reviewable commit-by-commit.

Copilot AI lite review requested due to automatic review settings September 1, 2026 19:50

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Shader does not see model's textures after engineReplaceModel Shaders doesn't work on replaced models sometime

2 participants