From 4fae8378db162aca235a68c467dbdf938bd91e0a Mon Sep 17 00:00:00 2001 From: Zero Fanker Date: Wed, 27 Nov 2024 22:11:51 -0500 Subject: [PATCH] focus lost fixing, also see 98e8b7c . --- MissionEditor/IsoView.cpp | 35 +++++++++++++++++++++++------------ MissionEditor/IsoView.h | 1 + 2 files changed, 24 insertions(+), 12 deletions(-) diff --git a/MissionEditor/IsoView.cpp b/MissionEditor/IsoView.cpp index ebdc857..7b0581c 100644 --- a/MissionEditor/IsoView.cpp +++ b/MissionEditor/IsoView.cpp @@ -5417,16 +5417,8 @@ void CIsoView::DrawMap() mapwidth = Map->GetWidth(); mapheight = Map->GetHeight(); - DDSURFACEDESC2 ddsd; - ZeroMemory(&ddsd, sizeof(ddsd)); - ddsd.dwSize = sizeof(DDSURFACEDESC2); - ddsd.dwFlags = DDSD_WIDTH | DDSD_HEIGHT; - - lpdsBack->GetSurfaceDesc(&ddsd); - - -#ifdef NOSURFACES - lpdsBack->Lock(NULL, &ddsd, DDLOCK_SURFACEMEMORYPTR | DDLOCK_WAIT | DDLOCK_NOSYSLOCK, NULL); +#ifdef NOSURFACES + auto ddsd = getDDDescBasic(false); #endif // we render texts and waypoints last as they should be always visible anyway and because text rendering is currently done using GDI -> getting a DC for every text is too slow nowadays @@ -6190,7 +6182,7 @@ void CIsoView::DrawMap() Blit((LPDIRECTDRAWSURFACE4)pics["CELLTAG"].pic, drawCoords.x - 1, drawCoords.y - 1); #ifdef NOSURFACES - lpdsBack->Lock(NULL, &ddsd, DDLOCK_SURFACEMEMORYPTR | DDLOCK_WAIT | DDLOCK_NOSYSLOCK, NULL); + auto ddsd = getDDDesc(false); #endif } @@ -6230,7 +6222,7 @@ void CIsoView::DrawMap() m_waypoints_to_render.push_back({ waypointImageCoords.x, waypointImageCoords.y }); m_texts_to_render.push_back({ ID.GetString(), waypointTextCoords.x, waypointTextCoords.y, RGB(0,0,255), false, useFont9, true }); #ifdef NOSURFACES - lpdsBack->Lock(NULL, &ddsd, DDLOCK_SURFACEMEMORYPTR | DDLOCK_WAIT | DDLOCK_NOSYSLOCK, NULL); + ddsd = getDDDescBasic(false); #endif } @@ -6322,6 +6314,25 @@ std::tuple CIsoView::getDDDesc(bool return { ddsd, dds, useHighRes }; } +DDSURFACEDESC2 CIsoView::getDDDescBasic(bool recreated) +{ + DDSURFACEDESC2 ddsd; + ZeroMemory(&ddsd, sizeof(ddsd)); + ddsd.dwSize = sizeof(DDSURFACEDESC2); + ddsd.dwFlags = DDSD_WIDTH | DDSD_HEIGHT; + + lpdsBack->GetSurfaceDesc(&ddsd); + + auto const lockRet = lpdsBack->Lock(NULL, &ddsd, DDLOCK_SURFACEMEMORYPTR | DDLOCK_WAIT | DDLOCK_NOSYSLOCK, NULL); + if (lockRet == DDERR_SURFACELOST && !recreated) { + ReInitializeDDraw(); + return getDDDescBasic(true); + } + ASSERT(lockRet == S_OK); + ASSERT(ddsd.lpSurface != nullptr); + return ddsd; +} + void CIsoView::RenderUIOverlay() { if (!m_textDefault) { diff --git a/MissionEditor/IsoView.h b/MissionEditor/IsoView.h index 6e72199..5bb60b8 100644 --- a/MissionEditor/IsoView.h +++ b/MissionEditor/IsoView.h @@ -123,6 +123,7 @@ protected: virtual void Dump(CDumpContext& dc) const; #endif std::tuple getDDDesc(bool recreated); + DDSURFACEDESC2 getDDDescBasic(bool recreated); // generated message maps //{{AFX_MSG(CIsoView)