Skip to content

fix(gta-core-five): safeguard b3751 gtaDrawable destructor - #4187

Open
Akimiyy wants to merge 1 commit into
citizenfx:masterfrom
Akimiyy:patch-3
Open

Akimiyy wants to merge 1 commit into
citizenfx:masterfrom
Akimiyy:patch-3

Conversation

@Akimiyy

@Akimiyy Akimiyy commented Sep 9, 2026

Copy link
Copy Markdown

Goal of this PR

This PR aims to resolve the unhandled ERR_MEM_MULTIALLOC_FREE crash 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/rmcDrawable destructor cycle within gta-core-five via an inline jitasm structure. 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 .rdata segments), the hook intercepts the operation and safely resets the address to nullptr, allowing the engine's built-in cleanup logic to skip the block rather than passing a static pointer into sysMemMultiAllocator::Free and 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

  • Code compiles and has been tested successfully.
  • Code explains itself well and/or is documented.
  • My commit message explains what the changes do and what they are for.
  • No extra compilation warnings are added by these changes.

Fixes issues

Fixes #4130

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.
@github-actions github-actions Bot added the invalid Requires changes before it's considered valid and can be (re)triaged label Sep 9, 2026
@Akimiyy Akimiyy changed the title fix(gta-core-five): safeguard b3751 gtaDrawable destructor against static pointers fix(gta-core-five): safeguard b3751 gtaDrawable destructor Sep 9, 2026
@github-actions github-actions Bot added triage Needs a preliminary assessment to determine the urgency and required action invalid Requires changes before it's considered valid and can be (re)triaged and removed invalid Requires changes before it's considered valid and can be (re)triaged triage Needs a preliminary assessment to determine the urgency and required action labels Sep 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

invalid Requires changes before it's considered valid and can be (re)triaged

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ERR_MEM_MULTIALLOC_FREE and clothes?

1 participant