Client crash / VRAM growth with heavy engineReplaceModel+engineImportTXD usage
Describe the bug
On a model-replacement-heavy server (hundreds of engineReplaceModel/engineImportTXD calls via a modloader), the client's D3D/texture memory grows over a session and eventually crashes to desktop (lost heartbeat / Timed out). Original crash was an assertion in densehashtable.h:782 (game_sa.dll), which points at ms_ModelTexturesInfoMap. This worked perfectly before the February 2026 TXD/model- texture replacement rework.
Symptoms / telemetry
- dx memory baseline ~620-685MB (tex ~410MB, font ~83-144MB, RT ~128MB) on 1920x1080.
- VRAM grows ~10-20MB/min in dense areas; element counts stay stable (~4330 objects), so it is NOT a Lua-side element leak.
- Crash reproduces faster with frequent reconnects (testing).
Build
client 1.6.0-9.24124.0 (latest). Includes 863241b, 61bc06c, c05dca9, 6632385, 985a815, 75ef610, 3fa6881, 64b3022 — yet the problem persists.
Repro
Heavy modloader replacing many object/vehicle/skin models at join via engineLoadTXD + engineImportTXD + engineLoadDFF + engineReplaceModel; drive across densely-replaced areas and/or reconnect repeatedly.
Steps to reproduce
- Run a server that replaces many models at join (objects, vehicles, skins) via engineLoadTXD + engineImportTXD + engineLoadDFF + engineReplaceModel (in our case a modloader handling hundreds of models).
- Join the server and let all custom models stream in.
- Drive/fly across densely-replaced areas; optionally open large full-screen UI and reconnect several times (as happens during development/testing).
- Watch dx memory (dxGetStatus / showmemstat) climb steadily over a few minutes (texture + render-target memory), while element counts stay constant.
- Client crashes to desktop after a few minutes — assertion densehashtable.h:782 in game_sa.dll, or a silent CTD; server reports lost heartbeat / Timed out.
Version
Client: 1.6.0-9.24124.0 (Windows 10/11, 64-bit) - latest build Server: 1.6 / 1.6.0-9.24124.0 - hosted at serverproject.pl (Linux 64-bit hosting) Not running Wine on the client.
Note: the crash is client-side (Windows). The client is on the latest build and already includes the post-Feb-2026 TXD fixes (863241b, 61bc06c, c05dca9, 6632385, 985a815, 75ef610, 3fa6881, 64b3022), yet the crash still occurs.
Additional context
- Original crash: assertion in densehashtable.h:782 (game_sa.dll), pointing at the model-texture replacement map (ms_ModelTexturesInfoMap) reworked in Feb 2026.
- The server ran fine for years and only started crashing after the February 2026 TXD / model-texture replacement rework.
- Not a Lua-side leak: element counts stay stable (~4330 objects) across sessions while dx texture/RT memory keeps climbing until the 32-bit process runs out of address space (GPU itself has ~3 GB free VRAM, RTX 5060).
- Reproduces much faster with frequent reconnects (typical during development).
- Related history: #4705 (engineImportTXD leak / crash after model restore, author states "memory leak during engineImportTXD was never fixed"), #359 (dev: "the TXD memory leak might still be there"), #4348/#4349 (engineReplaceModel leak/crash).
- Client is on the latest build and already includes the post-rework TXD fixes (863241b, 61bc06c, c05dca9, 6632385, 985a815, 75ef610, 3fa6881, 64b3022), yet the problem persists -> there appears to be a remaining leak/crash in this code path.
- Crash dump(s) attached above (MTA\dumps*.dmp).
Relevant log output
Classification: CLIENT_CRASH_SUSPECTED (lost heartbeat / QUIT: Timed out, graceful=false)
Client: 1.6.0-9.24124.0 | Server: 1.6 | Resources running: 200
Memory trend within a single ~3.7 min session (steady state, not first load):
VRAM: 612 -> 684 MB (+72 MB, ~20 MB/min)
Another session: 566 -> 623 MB (+57 MB)
Element counts stable (NOT a Lua element leak):
object ~4330 ped ~470 vehicle ~94
dxGetStatus snapshot at crash:
texMB = 410-412
fontMB = 83-144
rtMB = 128-130
total D3D ~ 620-685 MB (32-bit process)
freeMB (GPU) ~ 2920 (so GPU VRAM is NOT the limit)
fxQuality=2 psVer=3 anisotropic=0 windowed=false res=1920x1080
GPU: NVIDIA GeForce RTX 5060 Laptop GPU
Top object models in scene (one model dominates due to heavy replacement):
model 11892 x2025, 1265 x609, 2694 x595, 1230 x574, 12072 x507, ...
Workload: a modloader replacing hundreds of object/vehicle/skin models at join via
engineLoadTXD + engineImportTXD + engineLoadDFF + engineReplaceModel, with proper
engineRestoreModel / engineRestoreCOL / engineFreeModel / destroyElement on resource stop.
Reproduction is faster with repeated reconnects.
Security Policy
- [x] I have read and understood the Security Policy and this issue is not security related.
None of the referenced changes are in the latest build as the texture rework was reverted completely to its state as it was a year ago (see https://github.com/multitheftauto/mtasa-blue/pull/4807)
None of the referenced changes are in the latest build as the texture rework was reverted completely to its state as it was a year ago (see #4807)
Thanks for the clarification — understood that the Feb 2026 texture rework was fully reverted in #4807, so the commit hashes I referenced are no longer relevant. To confirm: we are already on the latest build, 1.6.0-9.24124.0 (June 2026), which is well after #4807 was merged (Apr 14). So our client already has the reverted (pre-Sept-2025) texture system — and the crash / VRAM growth still happens on this build under heavy engineImportTXD + engineReplaceModel usage (a modloader replacing hundreds of object/vehicle/skin models). So with the rework reverted, the remaining cause appears to be the longstanding engineImportTXD memory leak — is #4770 the correct issue to track this under? If so, I'm happy to move the discussion there and provide more data. Evidence it's still leaking on the current (post-revert) build:
- dx memory grows steadily within a single steady-state session (e.g. VRAM 612 -> 684 MB, ~20 MB/min) while element counts stay constant (~4330 objects) — so it is not a Lua-side element leak.
- dxGetStatus at crash: texMB ~410, fontMB ~83-144, rtMB ~128, total ~620-685 MB in the 32-bit process; GPU itself has ~3 GB free VRAM (RTX 5060).
- Reproduces faster with repeated reconnects (typical during development). Crash dump(s) attached. Happy to provide a minimal repro resource (modloader-style mass engineImportTXD/engineReplaceModel) if that helps.
I'm also experiencing this issue on my MTA server.
I have a custom vehicle loader that dynamically loads and replaces a large number of vehicle models and car parts using:
engineLoadTXD engineImportTXD engineLoadDFF engineReplaceModel
The problem becomes especially noticeable when loading a large number of custom vehicles and when models are repeatedly loaded/replaced during the client session.
I noticed that memory usage increases as more models are loaded/replaced. However, I found an interesting behavior: when I restart the resource responsible for loading the models, the memory usage is released and returns to its previous level.
Even after properly destroying the loaded elements and restoring the models, the memory usage does not return to its previous level. After repeated loading/unloading cycles, memory usage continues to increase and eventually the client crash.
This is particularly problematic for servers with a large custom vehicle fleet, where loading all models at once is not a practical solution.
I can also reproduce the issue consistently with repeated model loading, so it does not appear to be a Lua-side element leak.
It would be great if someone could investigate whether the texture/model data stored internally by the engine is being properly released after engineRestoreModel / destroying the TXD/DFF elements.
This issue is currently a major limitation for servers using a large number of custom models.
Nobody in this thread has confirmed if the issues are still present in latest (1.7). That will need to be done before we consider this issue.
Nobody in this thread has confirmed if the issues are still present in latest (1.7). That will need to be done before we consider this issue. I can confirm that the issue is still present in the latest MTA 1.7.
I tested it specifically with 1.7, and the behavior is unchanged: memory usage increases when loading/replacing models using engineLoadTXD, engineImportTXD, engineLoadDFF and engineReplaceModel.
Restarting the resource that handles the models still releases the accumulated memory and brings the memory usage back down.
So, as far as I can confirm, the issue is still reproducible in 1.7. @Lpsd
For TXD specifically I was not able to replicate #4770 as noted in the issue. Are you able to confirm how to replicate this differently or provide a resource?
I created this repository for testing. I've attached a link to download the .dff and .txd files. I think I found the cause while I was testing. @Lpsd
To test, use the command repro_repeat 40. Open Task Manager and check.
I tested on a dev-branch but also tested on mtasa-1.7-untested-26820-20260822 can confirm it still exists. https://youtu.be/us0eKEqfNwg (FLASHING WARNING)
Memory usage even after restore goes up each /repro_load + /repro_release or each /repro_cycle + /repro_release.
Looked into this with some counters compiled into the client. engineRestoreModel only puts the model geometry back - it never releases the textures the TXD element imported; that happens when the TXD element itself is destroyed, or when the resource stops. So the repro keeps a full copy of the TXD in VRAM for every cycle it runs. Add destroyElement for the TXD and the DFF elements and the growth is gone - after that I couldn't measure a leak anywhere on this path.
How I measured it, in more detail than anyone asked for (in-depth AI analysis, figures checked against the raw logs)
_
Harness. In-process counters sampled from Lua through a temporary perf-stat category, never process memory or dxGetStatus: live RenderWare texture/geometry counts, the texture-watch maps (STexInfo), the CTxdStore ref count of the target txd, the model-texture replacement map, and the D3D texture / vertex-buffer / index-buffer counts and bytes kept by MTA's device proxy, with created - destroyed == current checked on every sample (never failed). Build 1.7 custom, master cc3b35dee5, then the same runs with the game_sa.dll from my #4346 branch under identical client.dll/core.dll.
Tampay's repro as written (import + replace, engineRestoreModel, handles dropped, nothing destroyed): +25 textures / +942 080 B per cycle with a 25-texture DXT1 txd, +181 textures / +34 306 048 B per cycle with wheel.txd on the 35 upgrade models; every 50-cycle window identical. destroyElement on the kept elements afterwards returned every counter to its pre-block value (-3750 textures / -141 312 000 B in the small run, -724 / -137 224 192 B in the wheel run, txd ref count and map entries included). At the repro's cadence (one cycle per >= 6 s) that is about 340 MB/min, so /repro_repeat 40 runs the 32-bit process out of address space within minutes - which is also the resource-restart effect Tampay described, since a stop destroys the elements.
What actually frees what. engineRestoreModel -> CClientDFF::InternalRestoreModel: restreams, RestoreOriginalModel(), destroys the clump cached for that model id. Textures are untouched. destroyElement on the TXD element -> ~CClientTXD -> ModelInfoTXDRemoveTextures + restream: this is what releases the imported textures, and the only call sites of that function are in CClientTXD.cpp. destroyElement on the DFF element -> ~CClientDFF -> RestoreModels() + UnloadDFF(), so it restores whatever it replaced by itself; in my runs an explicit engineRestoreModel before it made no difference to any counter (measured both ways).
Same cycle with destroyElement: 150 cycles of import + destroy on two object models; 150 cycles of import + replace + restore + destroy (the DFF materials did resolve to the imported textures, 15 registrations per cycle on the branch build where I could count them); 8 full 35-model wheel.txd cycles (34 MB up and down each time); 60 cycles with an object of the replaced model on screen so the replaced clump was actually drawn before the restore (an index buffer created per cycle and released with it). Residual 0 in every live-object channel on both builds. The only non-zero readings: the D3D-pointer lookup index of the texture watch dropped by 2 once in the wheel run (a pre-existing stale-key condition), and twice the watch registered a batch of STexInfo in one go (+972 and +1654) during an idle or load-only phase, with no matching change in live textures. Both are streaming-side bookkeeping, not per-cycle growth.
Synthetic version of the original report (replace once at join, drive through replaced models, reconnect): the 35 wheel models replaced once, 700 MTA objects of them along a 2 km line with each model on its own stretch so whole models and their txd slots stream in and out, the player flying back and forth at 150 u/s with 175-315 objects streamed in at any time, counters every 5 s, three rounds of replace-all / drive 90 s / restore + destroy-all standing in for reconnects. On both builds no channel grew during any 90 s drive once first-draw instancing settled, each round returned to its start within a few streamed-in textures and geometries, and live texture counts ended at or below the starting value after all three rounds. That is 35 models on open sea without shaders or UI, so it bounds rather than closes the join-and-drive case.
Two source-level points for the original report. dxGetStatus's texture/font/render-target figures sum only MTA render items (CRenderItemManager::UpdateMemoryUsage: CFileTextureItem, CVectorGraphicItem, render targets, fonts), so textures loaded through engineLoadTXD never appear in them; the texMB/rtMB growth in the report lives in dxCreateTexture / shader / font / render-target objects. And densehashtable.h:782 is assert(table) right after a plain malloc in clear_to_size, i.e. the 32-bit process was out of address space while some dense_hash_map was being sized; it does not say which structure grew, and ms_ModelTexturesInfoMap is a std::map, so it cannot be that one.
On Task Manager. Process private bytes cannot settle a per-call question: in my earlier attempts it moved by several MB with nothing running and the slope changed sign with the window length. If someone has a cycle that still grows with destroyElement in place, I can run it through the same counters.
Not covered: raw RenderWare allocator bytes (unhooked), RwFrame / atomic / material objects (only RwTexture, RwRaster and RpGeometry are hooked), cube and volume textures, MTA-side D3D objects (created on the unproxied device), per-distinct-name growth in the shader texture list (#5301, every cycle here reuses the same names), and streaming pressure at the memory limit with thousands of replaced models. #5298 and #5301 address defects that need that pressure, so nothing above bears on them either way.
Two different things got mashed together here.
Tampay's repro isn't a leak. It never calls destroyElement. It loads the TXD and DFFs, calls engineRestoreModel, nils the Lua vars and expects magic. engineRestoreModel only puts the geometry back. The TXD and DFF elements stay alive until the resource stops, textures included. That's the whole "restart frees it" mystery.
The original report is a real bug though. CRenderWareSA::ReplaceModel calls SetClump, which AddRefs the model's TXD and anim block (CClumpModelInfo::SetClump, 0x4C4F70, does both), then dumps the old clump with a plain RpClumpDestroy. Only DeleteRwObject gives those refs back. MakeCustomModel runs ReplaceModel on every stream-in of a replaced vehicle, ped or weapon, so every stream-in leaks a ref and that TXD can never stream out again. Hundreds of replaced vehicles, drive around, VRAM only goes up, element counts flat. Exactly what RoLLberT3839 posted. Objects are fine, AtomicsReplacer already drops the ref.
Fix is #5411. #5404 only does the TXD half.
Now the "in-depth AI analysis" above. Six thousand characters of harness description, 150 cycles of counting live textures, a confident "couldn't measure a leak anywhere", and a footnote admitting it skipped half the things that matter. The leak is a refcount. Live object counters can't see a refcount. The same author then opened #5404 for this exact path two weeks later, so even they didn't buy it. Reading SetClump next to RpClumpDestroy takes one minute. Please stop pasting ChatGPT into issues and calling it analysis.