From 82716b247b40f8ca4304b9358232486bf5006033 Mon Sep 17 00:00:00 2001 From: m000z0rz Date: Wed, 20 May 2020 12:10:42 -0500 Subject: [PATCH 1/2] Prevent stack overflow by popping the pcall return value / error --- Source/Project64/UserInterface/Debugger/ScriptInstance.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Source/Project64/UserInterface/Debugger/ScriptInstance.cpp b/Source/Project64/UserInterface/Debugger/ScriptInstance.cpp index 0abb4bec6..b38eb40f7 100644 --- a/Source/Project64/UserInterface/Debugger/ScriptInstance.cpp +++ b/Source/Project64/UserInterface/Debugger/ScriptInstance.cpp @@ -465,6 +465,8 @@ void CScriptInstance::InvokeListenerCallback(IOLISTENER* lpListener) const char* msg = duk_safe_to_string(m_Ctx, -1); MessageBox(NULL, stdstr(msg).ToUTF16().c_str(), L"Script error", MB_OK | MB_ICONWARNING); } + + duk_pop(m_Ctx); } const char* CScriptInstance::Eval(const char* jsCode) From 9b9ab2af75e56587de2f217a8137da3cf9744ed0 Mon Sep 17 00:00:00 2001 From: m000z0rz Date: Wed, 20 May 2020 12:39:30 -0500 Subject: [PATCH 2/2] Fix script hanging when you stop a script with open listeners --- .../UserInterface/Debugger/ScriptInstance.cpp | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/Source/Project64/UserInterface/Debugger/ScriptInstance.cpp b/Source/Project64/UserInterface/Debugger/ScriptInstance.cpp index b38eb40f7..6bc9c174b 100644 --- a/Source/Project64/UserInterface/Debugger/ScriptInstance.cpp +++ b/Source/Project64/UserInterface/Debugger/ScriptInstance.cpp @@ -90,8 +90,11 @@ void CScriptInstance::ForceStop() { // Close all files and delete all hooked callbacks CGuard guard(m_CS); - CleanUp(); - SetState(STATE_STOPPED); + if (m_State != STATE_STOPPED) + { + CleanUp(); + SetState(STATE_STOPPED); + } } duk_context* CScriptInstance::DukContext() @@ -220,8 +223,7 @@ void CScriptInstance::StartEventLoop() RemoveListener(lpListener); } - CleanUp(); - SetState(STATE_STOPPED); + ForceStop(); } CScriptInstance::EVENT_STATUS @@ -529,8 +531,8 @@ void CScriptInstance::CloseAllFiles() for (size_t i = 0; i < nFiles; i++) { fclose(m_Files[i].fp); - m_Files.erase(m_Files.begin() + i); } + m_Files.clear(); } FILE* CScriptInstance::GetFilePointer(int fd)