Attempt to workaround rare crash that would happen when IDirect3DDevice9_Reset returns D3DERR_NOTAVAILABLE

This commit is contained in:
UnknownShadow200 2022-05-14 18:49:13 +10:00
parent 1ff3f481c4
commit a318d9ed98
2 changed files with 18 additions and 10 deletions

View File

@ -180,8 +180,10 @@ void Gfx_Create(void) {
}
cc_bool Gfx_TryRestoreContext(void) {
static int availFails;
D3DPRESENT_PARAMETERS args = { 0 };
cc_result res;
/* Rarely can't even create device to begin with */
if (!deviceCreated) {
TryCreateDevice();
@ -195,6 +197,12 @@ cc_bool Gfx_TryRestoreContext(void) {
res = IDirect3DDevice9_Reset(device, &args);
if (res == D3DERR_DEVICELOST) return false;
/* A user reported an issue where after changing some settings in */
/* nvidia control panel, IDirect3DDevice9_Reset would return */
/* D3DERR_NOTAVAILABLE and hence crash the game */
/* So try to workaround this by only crashing after 50 failures */
if (res == D3DERR_NOTAVAILABLE && availFails++ < 50) return false;
if (res) Logger_Abort2(res, "Error recreating D3D9 context");
D3D9_UpdateCachedDimensions();
return true;

View File

@ -337,22 +337,22 @@ void Launcher_LoadTheme(void) {
ParseColor("launcher-btn-highlight-inactive-col", &Launcher_Theme.ButtonHighlightColor);
}
CC_NOINLINE static void Launcher_SetCol(const char* key, BitmapCol col) {
cc_string value; char valueBuffer[8];
/* Component order might be different to BitmapCol */
PackedCol tmp = PackedCol_Make(BitmapCol_R(col), BitmapCol_G(col), BitmapCol_B(col), 0);
CC_NOINLINE static void SaveColor(const char* key, BitmapCol color) {
cc_string value; char valueBuffer[6];
String_InitArray(value, valueBuffer);
PackedCol_ToHex(&value, tmp);
String_AppendHex(&value, BitmapCol_R(color));
String_AppendHex(&value, BitmapCol_G(color));
String_AppendHex(&value, BitmapCol_B(color));
Options_Set(key, &value);
}
void Launcher_SaveTheme(void) {
Launcher_SetCol("launcher-back-col", Launcher_Theme.BackgroundColor);
Launcher_SetCol("launcher-btn-border-col", Launcher_Theme.ButtonBorderColor);
Launcher_SetCol("launcher-btn-fore-active-col", Launcher_Theme.ButtonForeActiveColor);
Launcher_SetCol("launcher-btn-fore-inactive-col", Launcher_Theme.ButtonForeColor);
Launcher_SetCol("launcher-btn-highlight-inactive-col", Launcher_Theme.ButtonHighlightColor);
SaveColor("launcher-back-col", Launcher_Theme.BackgroundColor);
SaveColor("launcher-btn-border-col", Launcher_Theme.ButtonBorderColor);
SaveColor("launcher-btn-fore-active-col", Launcher_Theme.ButtonForeActiveColor);
SaveColor("launcher-btn-fore-inactive-col", Launcher_Theme.ButtonForeColor);
SaveColor("launcher-btn-highlight-inactive-col", Launcher_Theme.ButtonHighlightColor);
Options_SetBool("nostalgia-classicbg", Launcher_Theme.ClassicBackground);
}