Skip to content

Commit

Permalink
Disable crash reporter when closing player. Crashes that happen after…
Browse files Browse the repository at this point in the history
… this are mostly in third party code, so avoid bothering users with an error and just close.
  • Loading branch information
clsid2 committed Jan 27, 2021
1 parent 2737edb commit 376b66b
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 12 deletions.
8 changes: 3 additions & 5 deletions include/version.h
Expand Up @@ -40,24 +40,22 @@
#endif
#endif

#ifndef NO_VERSION_REV_NEEDED
#ifdef NO_VERSION_REV_NEEDED
#define MPC_VERSION_REV 0
#else
#include "../build/version_rev.h"
#endif

#define MPC_VERSION_MAJOR 1
#define MPC_VERSION_MINOR 9
#define MPC_VERSION_PATCH 8

#ifndef NO_VERSION_REV_NEEDED

#if MPC_VERSION_REV > 0
#define MPC_NIGHTLY_RELEASE 1
#else
#define MPC_NIGHTLY_RELEASE 0
#endif

#endif // NO_VERSION_REV_NEEDED

#define MPC_COMP_NAME_STR _T("MPC-HC Team")
#define MPC_COPYRIGHT_STR _T("Copyright 2002-2021 clsid2 and others")
#define MPC_VERSION_COMMENTS WEBSITE_URL
Expand Down
6 changes: 4 additions & 2 deletions src/mpc-hc/AppSettings.cpp
Expand Up @@ -2368,9 +2368,11 @@ void CAppSettings::ParseCommandLine(CAtlList<CString>& cmdln)
fShowDebugInfo = true;
} else if (sw == _T("nocrashreporter")) {
#if USE_DRDUMP_CRASH_REPORTER
CrashReporter::Disable();
if (CrashReporter::IsEnabled()) {
CrashReporter::Disable();
MPCExceptionHandler::Enable();
}
#endif
MPCExceptionHandler::Enable();
} else if (sw == _T("audiorenderer") && pos) {
SetAudioRenderer(_ttoi(cmdln.GetNext(pos)));
} else if (sw == _T("shaderpreset") && pos) {
Expand Down
8 changes: 7 additions & 1 deletion src/mpc-hc/ExceptionHandler.cpp
Expand Up @@ -23,6 +23,7 @@
#include <windows.h>
#include <psapi.h>
#include <inttypes.h>
#include "mplayerc.h"

#ifndef _DEBUG

Expand Down Expand Up @@ -178,8 +179,13 @@ void HandleAccessViolation(LPEXCEPTION_POINTERS exceptionInfo)

LONG WINAPI UnhandledException(LPEXCEPTION_POINTERS exceptionInfo)
{
switch (exceptionInfo->ExceptionRecord->ExceptionCode) {
#if 1
if (AfxGetMyApp()->m_fClosingState) {
return EXCEPTION_EXECUTE_HANDLER;
}
#endif

switch (exceptionInfo->ExceptionRecord->ExceptionCode) {
case EXCEPTION_ACCESS_VIOLATION:
HandleAccessViolation(exceptionInfo);
break;
Expand Down
3 changes: 3 additions & 0 deletions src/mpc-hc/MainFrm.cpp
Expand Up @@ -1129,6 +1129,9 @@ void CMainFrame::OnClose()
s.UIceClient.DisConnect();

SendAPICommand(CMD_DISCONNECT, L"\0"); // according to CMD_NOTIFYENDOFSTREAM (ctrl+f it here), you're not supposed to send NULL here

AfxGetMyApp()->SetClosingState();

__super::OnClose();
}

Expand Down
25 changes: 21 additions & 4 deletions src/mpc-hc/mplayerc.cpp
Expand Up @@ -47,6 +47,7 @@
#include "ExceptionHandler.h"
#include "FGFilterLAV.h"
#include "CMPCThemeMsgBox.h"
#include "version.h"

HICON LoadIcon(CString fn, bool bSmallIcon, DpiHelper* pDpiHelper/* = nullptr*/)
{
Expand Down Expand Up @@ -1496,6 +1497,16 @@ BOOL RegQueryBoolValue(HKEY hKeyRoot, LPCWSTR lpSubKey, LPCWSTR lpValuename, BOO
return result;
}

#if USE_DRDUMP_CRASH_REPORTER
void DisableCrashReporter()
{
if (CrashReporter::IsEnabled()) {
CrashReporter::Disable();
MPCExceptionHandler::Enable();
}
}
#endif

BOOL CMPlayerCApp::InitInstance()
{
// Remove the working directory from the search path to work around the DLL preloading vulnerability
Expand Down Expand Up @@ -1814,9 +1825,8 @@ BOOL CMPlayerCApp::InitInstance()
m_s->LoadSettings(); // read settings

#if !defined(_DEBUG) && USE_DRDUMP_CRASH_REPORTER
if (!m_s->bEnableCrashReporter && CrashReporter::IsEnabled()) {
CrashReporter::Disable();
MPCExceptionHandler::Enable();
if (!m_s->bEnableCrashReporter) {
DisableCrashReporter();
}
#endif

Expand Down Expand Up @@ -2143,9 +2153,16 @@ void CMPlayerCApp::OnAppAbout()
aboutDlg.DoModal();
}

void CMPlayerCApp::OnFileExit()
void CMPlayerCApp::SetClosingState()
{
m_fClosingState = true;
#if USE_DRDUMP_CRASH_REPORTER & (MPC_VERSION_REV < 50)
DisableCrashReporter();
#endif
}

void CMPlayerCApp::OnFileExit()
{
OnAppExit();
}

Expand Down
3 changes: 3 additions & 0 deletions src/mpc-hc/mplayerc.h
Expand Up @@ -196,6 +196,9 @@ class CMPlayerCApp : public CWinAppEx
virtual BOOL InitInstance() override;
virtual int ExitInstance() override;

public:
void SetClosingState();

public:
DECLARE_MESSAGE_MAP()
afx_msg void OnAppAbout();
Expand Down

0 comments on commit 376b66b

Please sign in to comment.