Skip to content
This repository was archived by the owner on May 5, 2025. It is now read-only.

Commit b143354

Browse files
committed
Merge branch 'dev/lvengesanam/resolve_wndProc_issues' into 'main'
[REMIX-3328] Improve handling of recursive calls to WndProc callback procedure See merge request lightspeedrtx/bridge-remix-nv!116
2 parents 31bea36 + 0c0b8b1 commit b143354

File tree

3 files changed

+35
-41
lines changed

3 files changed

+35
-41
lines changed

src/client/d3d9_lss.cpp

Lines changed: 34 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ SceneState gSceneState = WaitBeginScene;
123123
std::chrono::steady_clock::time_point gTimeStart;
124124
bool gbBridgeRunning = true;
125125
std::string gRemixFolder = "";
126-
thread_local int gRemixWndProcEntryExitCount = 0;
126+
thread_local std::unordered_map<UINT, int> gRemixWndProcEntryExitCountMap;
127127

128128
void PrintRecentCommandHistory() {
129129
// Log history of recent client side commands sent and received by the server
@@ -468,35 +468,11 @@ LRESULT WINAPI RemixWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) {
468468
const bool isUnicode = IsWindowUnicode(hWnd);
469469

470470
LRESULT lresult = 0;
471-
gRemixWndProcEntryExitCount += 1;
472-
int curEntryExitCount = gRemixWndProcEntryExitCount;
473-
// Detecting recursive calls
474-
if (curEntryExitCount > 1) {
475-
int wndProcListLen = 0;
476-
{
477-
std::scoped_lock lock(gWndProcListMapMutex);
478-
if(ogWndProcList.find(hWnd) != ogWndProcList.end())
479-
wndProcListLen = ogWndProcList[hWnd].size();
480-
}
481-
int curWndProcIndex = curEntryExitCount-1;
482-
if (curWndProcIndex >= wndProcListLen) {
483-
gRemixWndProcEntryExitCount = 0;
484-
lresult = !isUnicode ?
485-
DefWindowProcA(hWnd, msg, wParam, lParam) :
486-
DefWindowProcW(hWnd, msg, wParam, lParam);
487-
}
488-
else {
489-
WNDPROC prevWndProc;
490-
{
491-
std::scoped_lock lock(gWndProcListMapMutex);
492-
prevWndProc = ogWndProcList[hWnd][curWndProcIndex];
493-
}
494-
lresult = !isUnicode ?
495-
CallWindowProcA(prevWndProc, hWnd, msg, wParam, lParam) :
496-
CallWindowProcW(prevWndProc, hWnd, msg, wParam, lParam);
497-
}
498-
}
499-
else {
471+
gRemixWndProcEntryExitCountMap[msg] += 1;
472+
int curEntryExitCount = gRemixWndProcEntryExitCountMap[msg];
473+
474+
if (curEntryExitCount == 1)
475+
{
500476
if (msg == WM_ACTIVATEAPP || msg == WM_SIZE || msg == WM_DESTROY) {
501477
gSwapChainMapMutex.lock();
502478
if (gSwapChainMap.find(hWnd) != gSwapChainMap.end()) {
@@ -549,7 +525,34 @@ LRESULT WINAPI RemixWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) {
549525
CallWindowProcW(prevWndProc, hWnd, msg, wParam, lParam);
550526
}
551527
}
552-
gRemixWndProcEntryExitCount -= 1;
528+
else {
529+
int wndProcListLen = 0;
530+
{
531+
std::scoped_lock lock(gWndProcListMapMutex);
532+
if(ogWndProcList.find(hWnd) != ogWndProcList.end())
533+
wndProcListLen = ogWndProcList[hWnd].size();
534+
}
535+
int curWndProcIndex = curEntryExitCount-1;
536+
if (curWndProcIndex >= wndProcListLen) {
537+
Logger::warn(logger_strings::WndProcExcessiveRecCall + std::to_string(msg) + " wParam: " + std::to_string(wParam));
538+
lresult = !isUnicode ?
539+
DefWindowProcA(hWnd, msg, wParam, lParam) :
540+
DefWindowProcW(hWnd, msg, wParam, lParam);
541+
}
542+
else {
543+
WNDPROC prevWndProc;
544+
{
545+
std::scoped_lock lock(gWndProcListMapMutex);
546+
prevWndProc = ogWndProcList[hWnd][curWndProcIndex];
547+
}
548+
lresult = !isUnicode ?
549+
CallWindowProcA(prevWndProc, hWnd, msg, wParam, lParam) :
550+
CallWindowProcW(prevWndProc, hWnd, msg, wParam, lParam);
551+
}
552+
}
553+
554+
gRemixWndProcEntryExitCountMap[msg] -= 1;
555+
553556
return lresult;
554557
}
555558

src/client/d3d9_swapchain.cpp

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -198,15 +198,6 @@ HRESULT Direct3DSwapChain9_LSS::Present(CONST RECT* pSourceRect, CONST RECT* pDe
198198
c.send_data(dwFlags);
199199
}
200200

201-
// Seeing this in the log could indicate the game is sending inputs to a different window
202-
extern std::unordered_map<HWND, std::deque<WNDPROC>> ogWndProcList;
203-
extern std::mutex gWndProcListMapMutex;
204-
if (hDestWindowOverride != NULL) {
205-
std::scoped_lock lock(gWndProcListMapMutex);
206-
if (ogWndProcList.find(hDestWindowOverride) == ogWndProcList.end())
207-
ONCE(Logger::info("Detected unhooked winproc on Direct3DSwapChain9::Present"));
208-
}
209-
210201
extern HRESULT syncOnPresent();
211202
const auto syncResult = syncOnPresent();
212203
if (syncResult == ERROR_SEM_TIMEOUT) {

src/util/log/log_strings.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ namespace logger_strings {
3030
constexpr char* MultipleActiveCommands = "Multiple active Command instances detected!";
3131
constexpr char* RtxRemixRuntimeError = "RTX Remix Runtime Error!";
3232
constexpr char* BridgeClientClosing = "The RTX Remix Runtime has encountered an unexpected issue. The application will close.\n\nPlease collect any *.log or *.dmp files next to the application or in the .trex folder, and report the error at https://github.com/NVIDIAGameWorks/rtx-remix/issues.";
33-
33+
constexpr char* WndProcExcessiveRecCall = "Detected excessive recursive calls to RemixWndProc - msg: ";
3434
inline static const std::map<const std::string, const std::string> bufferNameToOptionMap =
3535
{
3636
{"ModuleClient2ServerData", "moduleClientChannelMemSize"},

0 commit comments

Comments
 (0)