Conversation
The Issue (citizenfx#4130): On game build b3751, clients heavily streaming custom server assets (especially addon clothing packs on Canary) experience an unhandled ERR_MEM_MULTIALLOC_FREE crash. A full dump analysis revealed that during the asset unload path, the gtaDrawable/rmcDrawable destructor attempts to release its grmShaderGroup member located at offset +0x10. However, this pointer inadvertently points to a static address inside the executable image instead of a heap allocation. When passed down to sysMemMultiAllocator::Free, the engine recognizes that no active child allocator owns that specific memory block and deliberately triggers a fatal abort trap. The Resolution: This patch intercepts the destructor sequence right before the memory tracking query occurs. It introduces an inline jitasm structure that dynamically queries the game executable's base handle using Cfx utilities. It evaluates the shader-group pointer at [rdi + 0x10] against the process image boundaries. If the address falls within the fixed .rdata or .data segments of the running binary, the hook safely resets the member pointer to nullptr. This modification causes the standard cleanup routine to safely skip over the static pointer, altogether preventing the fatal memory manager exception without destabilizing other operational allocators.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Goal of this PR
This PR aims to resolve the unhandled
ERR_MEM_MULTIALLOC_FREEcrash occurring on game build b3751 when unloading custom server streamed assets, specifically associated with the user-reported crash hash scenario in issue #4130.How is this PR achieving the goal
It hooks the
gtaDrawable/rmcDrawabledestructor cycle withingta-core-fivevia an inlinejitasmstructure. The hook dynamically retrieves the game engine's executable boundaries using native Cfx utilities and evaluates the shader-group member pointer at[rdi + 0x10]. If this pointer inadvertently targets a static location inside the application image (such as fixed.rdatasegments), the hook intercepts the operation and safely resets the address tonullptr, allowing the engine's built-in cleanup logic to skip the block rather than passing a static pointer intosysMemMultiAllocator::Freeand triggering the intentional error trap.This PR applies to the following area(s)
FiveM
Successfully tested on
Game builds:
3751 (Canary Channel)
Platforms:
Windows
Checklist
Fixes issues
Fixes #4130