Skip to content

Commit

Permalink
Fixed DirectX9 reinitialisation
Browse files Browse the repository at this point in the history
BeebEm would revert to GDI rendering after the host PC
resumes from being suspended and, as reported in
issue #104 could in some case enter a loop continually
resetting the screen mode on entering full screen.

This commit adds handling for D3DERR_DEVICELOST
errors from IDirect3DDevice9::Present().
  • Loading branch information
chrisn committed May 30, 2024
1 parent 0cdb811 commit a386ec7
Show file tree
Hide file tree
Showing 4 changed files with 340 additions and 176 deletions.
26 changes: 24 additions & 2 deletions Src/BeebWin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -192,18 +192,33 @@ BeebWin::BeebWin()
m_printerbufferlen = 0;
m_translateCRLF = true;
m_CurrentDisplayRenderer = 0;
m_hInstDDraw = nullptr;
m_DD = nullptr;
m_DD2 = nullptr;
m_DDSPrimary = nullptr;
m_DDS2Primary = nullptr;
m_DDSOne = nullptr;
m_DDS2One = nullptr;
m_DXSmoothing = true;
m_DXSmoothMode7Only = false;
m_Clipper = nullptr;

m_pD3D = nullptr;
m_pd3dDevice = nullptr;
m_pVB = nullptr;
m_pTexture = nullptr;
ZeroMemory(&m_TextureMatrix, sizeof(m_TextureMatrix));

m_DXInit = false;
m_DXResetPending = false;
m_DXDeviceLost = false;

m_JoystickCaptured = false;
m_isFullScreen = false;
m_MaintainAspectRatio = true;
m_startFullScreen = false;
m_XDXSize = 640;
m_YDXSize = 480;
m_XScrSize = GetSystemMetrics(SM_CXSCREEN);
m_YScrSize = GetSystemMetrics(SM_CYSCREEN);
m_XWinBorder = GetSystemMetrics(SM_CXSIZEFRAME) * 2;
m_YWinBorder = GetSystemMetrics(SM_CYSIZEFRAME) * 2 +
GetSystemMetrics(SM_CYMENUSIZE) +
Expand Down Expand Up @@ -479,6 +494,8 @@ BeebWin::~BeebWin()
if (m_DisplayRenderer != IDM_DISPGDI)
ExitDX();

CloseDX9();

ReleaseDC(m_hWnd, m_hDC);

if (m_hOldObj != NULL)
Expand Down Expand Up @@ -2053,6 +2070,7 @@ LRESULT BeebWin::WndProc(UINT nMessage, WPARAM wParam, LPARAM lParam)
break;

case WM_REINITDX:
DebugTrace("WM_REINITDX\n");
ReinitDX();
break;

Expand All @@ -2077,6 +2095,10 @@ LRESULT BeebWin::WndProc(UINT nMessage, WPARAM wParam, LPARAM lParam)
userPortBreakoutDialog = nullptr;
break;

case WM_DIRECTX9_DEVICE_LOST:
OnDeviceLost();
break;

default: // Passes it on if unproccessed
return DefWindowProc(m_hWnd, nMessage, wParam, lParam);
}
Expand Down
14 changes: 8 additions & 6 deletions Src/BeebWin.h
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ class BeebWin {
void ShowMenu(bool on);
void HideMenu(bool hide);
void TrackPopupMenu(int x, int y);
bool IsFullScreen() { return m_isFullScreen; }
bool IsFullScreen() const { return m_isFullScreen; }
void ResetTiming(void);
int TranslateKey(int vkey, bool keyUp, int &row, int &col);
void ParseCommandLine(void);
Expand Down Expand Up @@ -330,12 +330,15 @@ class BeebWin {
// DirectDraw
HRESULT InitDirectDraw();
HRESULT InitSurfaces();
void ResetSurfaces();
void CloseSurfaces();

// DirectX9
HRESULT InitDX9();
void ExitDX9();
bool InitDX9();
void CloseDX9();
HRESULT InitD3DDevice();
void CloseD3DDevice();
void RenderDX9();
void OnDeviceLost();

void TranslateWindowSize(void);
void TranslateDDSize(void);
Expand Down Expand Up @@ -482,8 +485,6 @@ class BeebWin {
int m_YWinPos;
int m_XDXSize;
int m_YDXSize;
int m_XScrSize;
int m_YScrSize;
int m_XWinBorder;
int m_YWinBorder;
float m_XRatioAdj;
Expand Down Expand Up @@ -512,6 +513,7 @@ class BeebWin {
// DirectX stuff
bool m_DXInit;
bool m_DXResetPending;
bool m_DXDeviceLost;

// DirectDraw stuff
HINSTANCE m_hInstDDraw;
Expand Down
Loading

0 comments on commit a386ec7

Please sign in to comment.