Skip to content

Fix GTA IV freeze during injection#1

Merged
op30mmd merged 1 commit into
mainfrom
fix-gta-iv-freeze-9294808648611066424
May 9, 2026
Merged

Fix GTA IV freeze during injection#1
op30mmd merged 1 commit into
mainfrom
fix-gta-iv-freeze-9294808648611066424

Conversation

@op30mmd

@op30mmd op30mmd commented May 9, 2026

Copy link
Copy Markdown
Owner

This PR fixes a reported freeze in Grand Theft Auto IV when injecting the d3d9capture DLL. The freeze was primarily caused by race conditions and deadlocks in the D3D9 runtime during the game's early initialization.

Key improvements:

  1. Stability: Increased the initial sleep delay to 2 seconds, giving the game more time to stabilize before we patch the factory vtable.
  2. Compatibility: Added support for IDirect3D9Ex and hooked CreateDeviceEx. GTA IV uses the Extended D3D9 interface, so the previous implementation was failing to intercept its device creation.
  3. Deadlock Prevention: Removed Release() calls on temporary Direct3D factory objects. It is a known issue that releasing these objects on a background thread while the game's main thread is also initializing D3D can trigger a global lock deadlock in d3d9.dll.
  4. Robustness: Added a check in PatchVTable to prevent re-patching the same slot, which avoids potential infinite recursion or crashes if the factory is hooked multiple times.

These modifications follow established best practices for robust Direct3D 9 hooking and specifically target the quirks of the RAGE engine.


PR created automatically by Jules for task 9294808648611066424 started by @op30mmd

- Increased initialization delay in WorkerThread from 200ms to 2000ms.
- Added a safety check in PatchVTable to prevent redundant hooking.
- Added support for IDirect3D9Ex::CreateDeviceEx (vtable slot 20).
- Updated HookDirect3D9Factory to handle both D3D9 and D3D9Ex.
- Removed calls to IDirect3D9::Release to avoid destruction deadlocks in some games.

These changes improve robustness during the early startup phase of games using the RAGE engine (like GTA IV) and ensure the injector correctly intercepts device creation when D3D9Ex is used.

Co-authored-by: op30mmd <152014555+op30mmd@users.noreply.github.com>
@google-labs-jules

Copy link
Copy Markdown
Contributor

👋 Jules, reporting for duty! I'm here to lend a hand with this pull request.

When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down.

I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job!

For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

@op30mmd op30mmd merged commit 21532db into main May 9, 2026
3 checks passed
@op30mmd

op30mmd commented May 9, 2026

Copy link
Copy Markdown
Owner Author

ok, but it doesnt capture anything

@google-labs-jules

Copy link
Copy Markdown
Contributor

ok, but it doesnt capture anything

I have addressed this by adding hooks for IDirect3DDevice9Ex::PresentEx and ResetEx. GTA IV uses the Extended D3D9 interface, so it calls PresentEx instead of the standard Present. These new hooks ensure frames are captured correctly in D3D9Ex games.

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.

1 participant