Skip to content

Commit 632e1b9

Browse files
authored
bugfix(system): Prevent AMD/ATI driver crash on game launch by front loading the system dbghelp.dll (#1066)
1 parent 217b582 commit 632e1b9

File tree

26 files changed

+817
-164
lines changed

26 files changed

+817
-164
lines changed

CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ if((WIN32 OR "${CMAKE_SYSTEM}" MATCHES "Windows") AND ${CMAKE_SIZEOF_VOID_P} EQU
4343
include(cmake/miles.cmake)
4444
include(cmake/bink.cmake)
4545
include(cmake/dx8.cmake)
46-
include(cmake/dbghelp.cmake)
4746
endif()
4847

4948
# Define a dummy stlport target when not on VC6.

Core/Libraries/Source/WWVegas/WWLib/CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@ set(WWLIB_SRC
3232
#crcstraw.h
3333
cstraw.cpp
3434
cstraw.h
35+
DbgHelpGuard.cpp
36+
DbgHelpGuard.h
37+
DbgHelpLoader.cpp
38+
DbgHelpLoader.h
3539
Except.cpp
3640
Except.h
3741
FastAllocator.cpp
@@ -113,6 +117,7 @@ set(WWLIB_SRC
113117
strtok_r.cpp
114118
strtok_r.h
115119
#swap.h
120+
SystemAllocator.h
116121
systimer.cpp
117122
systimer.h
118123
TARGA.cpp
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
/*
2+
** Command & Conquer Generals Zero Hour(tm)
3+
** Copyright 2025 TheSuperHackers
4+
**
5+
** This program is free software: you can redistribute it and/or modify
6+
** it under the terms of the GNU General Public License as published by
7+
** the Free Software Foundation, either version 3 of the License, or
8+
** (at your option) any later version.
9+
**
10+
** This program is distributed in the hope that it will be useful,
11+
** but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
** GNU General Public License for more details.
14+
**
15+
** You should have received a copy of the GNU General Public License
16+
** along with this program. If not, see <http://www.gnu.org/licenses/>.
17+
*/
18+
19+
#include "DbgHelpGuard.h"
20+
21+
#include "DbgHelpLoader.h"
22+
23+
24+
DbgHelpGuard::DbgHelpGuard()
25+
: m_hasLoaded(false)
26+
{
27+
activate();
28+
}
29+
30+
DbgHelpGuard::~DbgHelpGuard()
31+
{
32+
deactivate();
33+
}
34+
35+
void DbgHelpGuard::activate()
36+
{
37+
if (DbgHelpLoader::isLoadedFromSystem())
38+
{
39+
// This is ok. Do nothing.
40+
}
41+
else if (DbgHelpLoader::isLoaded())
42+
{
43+
// This is maybe not ok. But do nothing until this becomes a user facing problem.
44+
}
45+
else
46+
{
47+
// Front load the DLL now to prevent other code from loading the potentially wrong DLL.
48+
m_hasLoaded = DbgHelpLoader::load();
49+
}
50+
}
51+
52+
void DbgHelpGuard::deactivate()
53+
{
54+
if (m_hasLoaded)
55+
{
56+
DbgHelpLoader::unload();
57+
m_hasLoaded = false;
58+
}
59+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/*
2+
** Command & Conquer Generals Zero Hour(tm)
3+
** Copyright 2025 TheSuperHackers
4+
**
5+
** This program is free software: you can redistribute it and/or modify
6+
** it under the terms of the GNU General Public License as published by
7+
** the Free Software Foundation, either version 3 of the License, or
8+
** (at your option) any later version.
9+
**
10+
** This program is distributed in the hope that it will be useful,
11+
** but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
** GNU General Public License for more details.
14+
**
15+
** You should have received a copy of the GNU General Public License
16+
** along with this program. If not, see <http://www.gnu.org/licenses/>.
17+
*/
18+
19+
#pragma once
20+
21+
#include "always.h"
22+
23+
24+
// This class temporarily loads and unloads dbghelp.dll from the desired location to prevent
25+
// other code from potentially loading it from an undesired location.
26+
// This helps avoid crashing on boot using recent AMD/ATI drivers, which attempt to load and use
27+
// dbghelp.dll from the game install directory but are unable to do so without crashing because
28+
// the dbghelp.dll that ships with the game is very old and the AMD/ATI code does not handle
29+
// that correctly.
30+
31+
class DbgHelpGuard
32+
{
33+
public:
34+
35+
DbgHelpGuard();
36+
~DbgHelpGuard();
37+
38+
void activate();
39+
void deactivate();
40+
41+
private:
42+
43+
bool m_hasLoaded;
44+
};

0 commit comments

Comments
 (0)