Corrected nullptr crash on Windows when going to sleep

This commit is contained in:
Jonathan White 2017-05-06 22:14:53 -04:00 committed by thez3ro
parent 8ddd0b2f6f
commit 147c000ef1
No known key found for this signature in database
GPG Key ID: F628F9E41DD7C073

View File

@ -45,13 +45,18 @@ bool ScreenLockListenerWin::nativeEventFilter(const QByteArray &eventType, void
if (eventType == "windows_generic_MSG" || eventType == "windows_dispatcher_MSG") { if (eventType == "windows_generic_MSG" || eventType == "windows_dispatcher_MSG") {
MSG* m = static_cast<MSG *>(message); MSG* m = static_cast<MSG *>(message);
if (m->message == WM_POWERBROADCAST) { if (m->message == WM_POWERBROADCAST) {
const POWERBROADCAST_SETTING* setting = reinterpret_cast<const POWERBROADCAST_SETTING*>(m->lParam); if (m->wParam == PBT_POWERSETTINGCHANGE) {
if (setting->PowerSetting == GUID_LIDSWITCH_STATE_CHANGE) { const POWERBROADCAST_SETTING* setting = reinterpret_cast<const POWERBROADCAST_SETTING*>(m->lParam);
const DWORD* state = reinterpret_cast<const DWORD*>(&setting->Data); if (setting != nullptr && setting->PowerSetting == GUID_LIDSWITCH_STATE_CHANGE) {
if (*state == 0) { const DWORD* state = reinterpret_cast<const DWORD*>(&setting->Data);
Q_EMIT screenLocked(); if (*state == 0) {
return true; Q_EMIT screenLocked();
return true;
}
} }
} else if (m->wParam == PBT_APMSUSPEND) {
Q_EMIT screenLocked();
return true;
} }
} }
if (m->message == WM_WTSSESSION_CHANGE) { if (m->message == WM_WTSSESSION_CHANGE) {