Repository navigation
feat(crashreporting): Add optional local Crashpad backend #3413
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
CryoTheRenegade
wants to merge
6
commits into
TheSuperHackers:main
Choose a base branch
from
CryoTheRenegade:feat/crashpad
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+759
−30
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
5c76d20
feat(crashreporting): Add optional local Crashpad backend
CryoTheRenegade 56e944e
docs(crashpad): Keep local validation results out of the PR
CryoTheRenegade 5efe454
ci(vcpkg): Select the root dependency manifest explicitly
CryoTheRenegade ec660df
bugfix(crashreporting): Preserve fatal dumps during shutdown
CryoTheRenegade 160053c
refactor(crashreporting): Simplify optional Crashpad integration
CryoTheRenegade 32191bc
refactor(crashreporting): Remove redundant helpers and reuse scoped h…
CryoTheRenegade File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| /* | ||
| ** Command & Conquer Generals Zero Hour(tm) | ||
| ** Copyright 2026 TheSuperHackers | ||
| ** | ||
| ** This program is free software: you can redistribute it and/or modify | ||
| ** it under the terms of the GNU General Public License as published by | ||
| ** the Free Software Foundation, either version 3 of the License, or | ||
| ** (at your option) any later version. | ||
| ** | ||
| ** This program is distributed in the hope that it will be useful, | ||
| ** but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| ** GNU General Public License for more details. | ||
| ** | ||
| ** You should have received a copy of the GNU General Public License | ||
| ** along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
| */ | ||
|
|
||
| #pragma once | ||
|
|
||
| class AsciiString; | ||
|
|
||
| // Keep this interface compatible with VC6 and tools that only use MiniDumper. | ||
| namespace CrashReporting | ||
| { | ||
| void initialize(const AsciiString& userDirectory, int major, int minor, int build); | ||
| void userDirectoryReady(const AsciiString& userDirectory); | ||
| void captureFatal(); | ||
| void shutdown(); | ||
| } |
161 changes: 161 additions & 0 deletions
161
Core/GameEngine/Source/Common/System/CrashReporting.cpp
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,161 @@ | ||
| /* | ||
| ** Command & Conquer Generals Zero Hour(tm) | ||
| ** Copyright 2026 TheSuperHackers | ||
| ** | ||
| ** This program is free software: you can redistribute it and/or modify | ||
| ** it under the terms of the GNU General Public License as published by | ||
| ** the Free Software Foundation, either version 3 of the License, or | ||
| ** (at your option) any later version. | ||
| ** | ||
| ** This program is distributed in the hope that it will be useful, | ||
| ** but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| ** GNU General Public License for more details. | ||
| ** | ||
| ** You should have received a copy of the GNU General Public License | ||
| ** along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
| */ | ||
|
|
||
| // TheSuperHackers @feature Codex 01/10/2026 Select optional local Crashpad reporting with legacy MiniDumper fallback. | ||
| #include "PreRTS.h" // This must go first in EVERY cpp file in the GameEngine | ||
| #include "Common/CrashReporting.h" | ||
| #include "Common/MiniDumper.h" | ||
|
|
||
| #ifdef RTS_USE_CRASHPAD | ||
| #include "CrashpadBridge.h" | ||
| #include "gitinfo.h" | ||
|
|
||
| namespace | ||
| { | ||
| RtsCrashpadCaptureFatalFunction capture; | ||
| RtsCrashpadShutdownFunction stop; | ||
| bool awaitingUserDirectory; | ||
| int savedMajor; | ||
| int savedMinor; | ||
| int savedBuild; | ||
|
|
||
| bool StartCrashpad(const AsciiString& userDirectory, int major, int minor, int build) | ||
| { | ||
| wchar_t path[32768]; | ||
| const DWORD count = GetModuleFileNameW(nullptr, path, ARRAY_SIZE(path)); | ||
| if (!count || count >= ARRAY_SIZE(path)) | ||
| { | ||
| return false; | ||
| } | ||
|
|
||
| wchar_t* leaf = wcsrchr(path, L'\\'); | ||
| const wchar_t name[] = L"rts_crashpad.dll"; | ||
| if (!leaf || (leaf + 1 - path) + ARRAY_SIZE(name) > ARRAY_SIZE(path)) | ||
| { | ||
| return false; | ||
| } | ||
|
|
||
| memcpy(leaf + 1, name, sizeof(name)); | ||
| HMODULE module = LoadLibraryExW(path, nullptr, LOAD_WITH_ALTERED_SEARCH_PATH); | ||
| if (!module) | ||
| { | ||
| return false; | ||
| } | ||
|
|
||
| RtsCrashpadInitializeFunction start = reinterpret_cast<RtsCrashpadInitializeFunction>( | ||
| GetProcAddress(module, "RtsCrashpadInitialize")); | ||
| capture = reinterpret_cast<RtsCrashpadCaptureFatalFunction>(GetProcAddress(module, "RtsCrashpadCaptureFatal")); | ||
| stop = reinterpret_cast<RtsCrashpadShutdownFunction>(GetProcAddress(module, "RtsCrashpadShutdown")); | ||
| char version[64]; | ||
| snprintf(version, ARRAY_SIZE(version), "%d.%d.%d", major, minor, build); | ||
| #if RTS_ZEROHOUR | ||
| const char* game = "Zero Hour"; | ||
| #else | ||
| const char* game = "Generals"; | ||
| #endif | ||
| if (start && capture && stop && start(userDirectory.str(), game, version, GitSHA1, GitUncommittedChanges)) | ||
| { | ||
| return true; | ||
| } | ||
|
|
||
| // Crashpad retains process-lifetime pointers even after failed startup. | ||
| // Keep the module loaded; its initializer restores the previous filter. | ||
| capture = nullptr; | ||
| stop = nullptr; | ||
| return false; | ||
| } | ||
| } | ||
| #endif | ||
|
|
||
| void CrashReporting::initialize(const AsciiString& userDirectory, int major, int minor, int build) | ||
| { | ||
| #ifdef RTS_USE_CRASHPAD | ||
| // Generals resolves UserDataLeafName from GameData.ini during engine init. | ||
| // Zero Hour already has its registry-derived path at WinMain startup. | ||
| awaitingUserDirectory = userDirectory.isEmpty(); | ||
| savedMajor = major; | ||
| savedMinor = minor; | ||
| savedBuild = build; | ||
| if (!awaitingUserDirectory && StartCrashpad(userDirectory, major, minor, build)) | ||
| { | ||
| OutputDebugStringA("Crash reporting: Crashpad (local only)\n"); | ||
| DEBUG_LOG(("Crash reporting: Crashpad (local only)\n")); | ||
| return; | ||
| } | ||
|
|
||
| if (!awaitingUserDirectory) | ||
| { | ||
| OutputDebugStringA("Crashpad startup failed; trying MiniDumper\n"); | ||
| DEBUG_LOG(("Crashpad startup failed; trying MiniDumper\n")); | ||
| } | ||
| #endif | ||
| #ifdef RTS_ENABLE_CRASHDUMP | ||
| MiniDumper::initMiniDumper(userDirectory); | ||
| DEBUG_LOG(("Crash reporting: %s\n", | ||
| TheMiniDumper && TheMiniDumper->IsInitialized() ? "minidumper" : "unavailable")); | ||
| #endif | ||
| } | ||
|
|
||
| void CrashReporting::userDirectoryReady(const AsciiString& userDirectory) | ||
| { | ||
| #ifdef RTS_USE_CRASHPAD | ||
| // Tools never call initialize(), so this cannot start Crashpad in a tool. | ||
| if (awaitingUserDirectory && !userDirectory.isEmpty()) | ||
| { | ||
| MiniDumper::shutdownMiniDumper(); | ||
| initialize(userDirectory, savedMajor, savedMinor, savedBuild); | ||
| } | ||
| #endif | ||
| } | ||
|
|
||
| void CrashReporting::captureFatal() | ||
| { | ||
| #ifdef RTS_USE_CRASHPAD | ||
| if (capture) | ||
| { | ||
| capture(); | ||
| return; | ||
| } | ||
| #endif | ||
| #ifdef RTS_ENABLE_CRASHDUMP | ||
| if (TheMiniDumper && TheMiniDumper->IsInitialized()) | ||
| { | ||
| // Preserve both minimal and full memory dumps for the legacy backend. | ||
| TheMiniDumper->TriggerMiniDump(DumpType_Minimal); | ||
| TheMiniDumper->TriggerMiniDump(DumpType_Full); | ||
| } | ||
|
|
||
| MiniDumper::shutdownMiniDumper(); | ||
| #endif | ||
| } | ||
|
|
||
| void CrashReporting::shutdown() | ||
| { | ||
| #ifdef RTS_USE_CRASHPAD | ||
| awaitingUserDirectory = false; | ||
| if (stop) | ||
| { | ||
| stop(); | ||
| stop = nullptr; | ||
| capture = nullptr; | ||
| } | ||
| #endif | ||
| #ifdef RTS_ENABLE_CRASHDUMP | ||
| MiniDumper::shutdownMiniDumper(); | ||
| #endif | ||
| } |
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
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
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.