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

Closed
opened 2026-11-26 20:17:24 +01:00 by 4ld0 · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/ubiquitarianism/leonida/pull/239
Author: @natterman12
Created: 11/24/2026
Status: ✅ Merged
Merged: 11/24/2026
Merged by: @ubiquitarianism

Base: main ← Head: runtime/compat-load-no-error-dialog


📝 Commits (1)

  • 682fd05 pe_loader: a compat DLL Windows cannot load is refused without a "Bad Image" box

📊 Changes

2 files changed (+28 additions, -1 deletions)

View changed files

📝 runtime/src/pe_loader.cpp (+8 -1)
📝 runtime/test/loader_test.cpp (+20 -0)

📄 Description

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


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/ubiquitarianism/leonida/pull/239 **Author:** [@natterman12](https://github.com/natterman12) **Created:** 11/24/2026 **Status:** ✅ Merged **Merged:** 11/24/2026 **Merged by:** [@ubiquitarianism](https://github.com/ubiquitarianism) **Base:** `main` ← **Head:** `runtime/compat-load-no-error-dialog` --- ### 📝 Commits (1) - [`682fd05`](https://github.com/ubiquitarianism/leonida/commit/682fd0561cd5e649d199adb9633b81b26baf26a6) pe_loader: a compat DLL Windows cannot load is refused without a "Bad Image" box ### 📊 Changes **2 files changed** (+28 additions, -1 deletions) <details> <summary>View changed files</summary> 📝 `runtime/src/pe_loader.cpp` (+8 -1) 📝 `runtime/test/loader_test.cpp` (+20 -0) </details> ### 📄 Description 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) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
4ld0 2026-11-26 20:17:24 +01:00
Sign in to join this conversation.
No labels
bug
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
starred/leonida#292
No description provided.