pe_loader: a compat DLL Windows cannot load is refused without a "Bad Image" box (RT-COMPAT-ERRBOX) #239

Manually merged
github merged 1 commit from gh-pr/239/head into gh-pr/239/base 2026-11-26 08:50:01 +00:00
Owner

@⁠natterman12 on GitHub · 2026-11-24 02:51 UTC · original
runtime/compat-load-no-error-dialog → main · +28 −1 · 2 files · 1 commits · merged 2026-11-24 03:36 UTC

Claimed in the coordination issue as: RT-COMPAT-ERRBOX (#14)

What and why

Loader::resolve_compat() loads a drop-in DLL from LEONIDA_COMPAT_DIR with LoadLibraryExW. When Windows cannot map the file (truncated, wrong machine, not a PE image), the system raises a modal "Bad Image" hard-error box (status 0xc000012f) and LoadLibraryExW does not return until someone clicks OK.

The loader already reports that failure itself on the next line ("LEONIDA_COMPAT_DIR: ... exists but Windows could not load it (error N)"), so the box adds nothing and costs two things:

  • gta6rt with a broken file in the compat folder hangs on a machine with nobody at it;
  • loader_test writes exactly such a file on purpose (compat_bad/testcompat.dll, 64 bytes of 0x5A), so every unattended ctest run on Windows stops at the loader test until the box is dismissed. Seven other runtime tests set SEM_FAILCRITICALERRORS for themselves; here the fix belongs in the loader, since the runtime has the same problem.

The load now runs with SEM_FAILCRITICALERRORS added to the calling thread's error mode (SetThreadErrorMode, so other threads are unaffected), and the previous mode is restored afterwards. GetLastError() is read before the mode is put back, so the reported code is the load's own.

loader_test gains three checks on the existing bad-file case: the thread's error mode is unchanged afterwards (the case starts from a mode without SEM_FAILCRITICALERRORS, so a loader that suppresses nothing would show the box), the message still carries a non-zero Windows error code, and the refusal returns within 5 s rather than waiting on a box.

Tested

Windows 11 (10.0.26300), Visual Studio Build Tools 2022 (MSVC 19.44.35230), NVIDIA RTX 3080 Ti, driver 621.24. No game files.

  • Before, on main da60a3615: the "loader_test.exe - Bad Image" box appeared during ctest and the loader test took 28.69 s, the wait for the click.
  • After, on this branch: loader_test.exe run directly finishes in 9 s with no box, 95 checks, 0 failed, including the three new ones.
  • I did not rebuild the unfixed loader with the new checks to watch them fail, because that run puts the box back on the desktop; the "before" evidence is the run above.
  • Built only loader_test (which links the loader) on this branch; the full runtime suite was run on main, not on this branch. Not tested under Wine, where the box does not appear in the first place.

AI-assisted: yes (Claude Code)

Checklist

  • No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here.
  • A new translator rule is in the contract table of docs/design.md, with how it was confirmed. (not applicable: no translator change)

🤖 Generated with Claude Code

**@⁠natterman12** on GitHub · 2026-11-24 02:51 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/239) `runtime/compat-load-no-error-dialog` → `main` · +28 −1 · 2 files · 1 commits · merged 2026-11-24 03:36 UTC Claimed in the coordination issue as: RT-COMPAT-ERRBOX (#14) ### What and why `Loader::resolve_compat()` loads a drop-in DLL from `LEONIDA_COMPAT_DIR` with `LoadLibraryExW`. When Windows cannot map the file (truncated, wrong machine, not a PE image), the system raises a modal "Bad Image" hard-error box (status 0xc000012f) and `LoadLibraryExW` does not return until someone clicks OK. The loader already reports that failure itself on the next line ("LEONIDA_COMPAT_DIR: ... exists but Windows could not load it (error N)"), so the box adds nothing and costs two things: - `gta6rt` with a broken file in the compat folder hangs on a machine with nobody at it; - `loader_test` writes exactly such a file on purpose (`compat_bad/testcompat.dll`, 64 bytes of 0x5A), so every unattended `ctest` run on Windows stops at the `loader` test until the box is dismissed. Seven other runtime tests set `SEM_FAILCRITICALERRORS` for themselves; here the fix belongs in the loader, since the runtime has the same problem. The load now runs with `SEM_FAILCRITICALERRORS` added to the calling thread's error mode (`SetThreadErrorMode`, so other threads are unaffected), and the previous mode is restored afterwards. `GetLastError()` is read before the mode is put back, so the reported code is the load's own. `loader_test` gains three checks on the existing bad-file case: the thread's error mode is unchanged afterwards (the case starts from a mode without `SEM_FAILCRITICALERRORS`, so a loader that suppresses nothing would show the box), the message still carries a non-zero Windows error code, and the refusal returns within 5 s rather than waiting on a box. ### Tested Windows 11 (10.0.26300), Visual Studio Build Tools 2022 (MSVC 19.44.35230), NVIDIA RTX 3080 Ti, driver 621.24. No game files. - Before, on `main` da60a3615: the "loader_test.exe - Bad Image" box appeared during `ctest` and the `loader` test took 28.69 s, the wait for the click. - After, on this branch: `loader_test.exe` run directly finishes in 9 s with no box, `95 checks, 0 failed`, including the three new ones. - I did not rebuild the unfixed loader with the new checks to watch them fail, because that run puts the box back on the desktop; the "before" evidence is the run above. - Built only `loader_test` (which links the loader) on this branch; the full runtime suite was run on `main`, not on this branch. Not tested under Wine, where the box does not appear in the first place. AI-assisted: yes (Claude Code) ### Checklist - [x] No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here. - [ ] A new translator rule is in the contract table of `docs/design.md`, with how it was confirmed. (not applicable: no translator change) 🤖 Generated with [Claude Code](https://claude.com/claude-code)
resolve_compat() calls LoadLibraryExW on a file from LEONIDA_COMPAT_DIR. For
a file Windows cannot map (truncated, wrong machine, not a PE image) the
system raises a modal "Bad Image" hard-error box, and LoadLibraryExW does
not return until someone clicks OK. The loader reports that failure itself
one line later, so the box only stalls it: gta6rt hangs on a headless
machine, and loader_test, which writes such a file on purpose, waits for a
click in every unattended ctest run.

The load now runs with SEM_FAILCRITICALERRORS set on the calling thread, and
the thread's previous error mode is restored afterwards. The Windows error
code is read before the mode is put back.

loader_test checks that the mode comes back unchanged, that the message
still carries the error code, and that the refusal does not wait on a box.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 08:49:59 +00:00
github manually merged commit 682fd0561c into gh-pr/239/base 2026-11-26 08:50:01 +00:00
This discussion has been locked. Commenting is limited to contributors.
No description provided.