Skip to content

fix: dxDrawModel3D flickering issue#4784

Open
naouh wants to merge 7 commits intomultitheftauto:release/1.6.0from
naouh:fix/dxDrawModel3D
Open

fix: dxDrawModel3D flickering issue#4784
naouh wants to merge 7 commits intomultitheftauto:release/1.6.0from
naouh:fix/dxDrawModel3D

Conversation

@naouh
Copy link
Copy Markdown

@naouh naouh commented Apr 9, 2026

Summary

Fix dxDrawModel3D flickering when rendering a model

Motivation

Commit e5e308de1 ("GTA streamer bug-fix round #1") added ModelAddRef/RemoveRef inside RenderModel() to protect the RwObject from being GC'd during rendering. The problem is that RemoveRef does more than just decrement a counter, when MTA's m_dwReferences hits 0, it calls Remove(), which decrements GTA's usNumberOfRefs and if that also reaches 0, fires RemoveModel() and unloads the model.

With dxDrawModel3D, no persistent MTA-side reference is held, so every single frame:

  1. ModelAddRef bumps refs 0 → 1
  2. Model renders
  3. RemoveRef drops refs 1 → 0 → Remove() → model unloaded
  4. Next frame: model gone, EnqueueModel fails, nothing renders
  5. engineStreamingRequestModel re-requests it, model reloads
  6. Next frame: renders, then unloads again → repeat

Hence the flickering every other frame.

The fix replaces ModelAddRef/RemoveRef with a direct increment/decrement of GTA's usNumberOfRefs, which still blocks the streaming GC from freeing the model mid-render without triggering MTA's unload logic on release.

Test plan

Test with the Maybe v4 resource, objects that were flickering should now render stable.

[DM]Maybe_v4-_Saints_Boulevard.zip

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.

@FileEX FileEX linked an issue Apr 9, 2026 that may be closed by this pull request
1 task
@FileEX FileEX added the bugfix Solution to a bug of any kind label Apr 9, 2026
@naouh naouh requested a review from FileEX April 9, 2026 17:29
@naouh naouh requested a review from FileEX April 10, 2026 15:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bugfix Solution to a bug of any kind

Projects

None yet

Development

Successfully merging this pull request may close these issues.

dxDrawModel3D flickering

3 participants