Fix crash with event loop nesting.

This commit is contained in:
John Preston 2018-12-25 14:11:10 +04:00
parent a65afdac95
commit d1be4c6d96
5 changed files with 15 additions and 28 deletions

View File

@ -390,7 +390,20 @@ void Application::refreshGlobalProxy() {
void Application::postponeCall(FnMut<void()> &&callable) {
Expects(callable != nullptr);
Expects(_eventNestingLevel > _loopNestingLevel);
Expects(_eventNestingLevel >= _loopNestingLevel);
// _loopNestingLevel == _eventNestingLevel means that we had a
// native event in a nesting loop that didn't get a notify() call
// after. That means we already have exited the nesting loop and
// there must not be any postponed calls with that nesting level.
if (_loopNestingLevel == _eventNestingLevel) {
Assert(_postponedCalls.empty()
|| _postponedCalls.back().loopNestingLevel < _loopNestingLevel);
Assert(!_previousLoopNestingLevels.empty());
_loopNestingLevel = _previousLoopNestingLevels.back();
_previousLoopNestingLevels.pop_back();
}
_postponedCalls.push_back({
_loopNestingLevel,
@ -430,8 +443,7 @@ bool Application::nativeEventFilter(
const QByteArray &eventType,
void *message,
long *result) {
if (_eventNestingLevel > _loopNestingLevel
&& Platform::NativeEventNestsLoop(message)) {
if (_eventNestingLevel > _loopNestingLevel) {
_previousLoopNestingLevels.push_back(_loopNestingLevel);
_loopNestingLevel = _eventNestingLevel;
}

View File

@ -488,10 +488,6 @@ void RequestPermission(PermissionType type, Fn<void(PermissionStatus)> resultCal
void OpenSystemSettingsForPermission(PermissionType type) {
}
bool NativeEventNestsLoop(void *message) {
return true;
}
namespace ThirdParty {
void start() {

View File

@ -332,10 +332,6 @@ void OpenSystemSettingsForPermission(PermissionType type) {
#endif // OS_MAC_OLD
}
bool NativeEventNestsLoop(void *message) {
return true;
}
} // namespace Platform
void psNewVersion() {

View File

@ -35,8 +35,6 @@ PermissionStatus GetPermissionStatus(PermissionType type);
void RequestPermission(PermissionType type, Fn<void(PermissionStatus)> resultCallback);
void OpenSystemSettingsForPermission(PermissionType type);
bool NativeEventNestsLoop(void *message);
QString SystemLanguage();
QString SystemCountry();

View File

@ -657,21 +657,6 @@ void OpenSystemSettingsForPermission(PermissionType type) {
}
}
bool NativeEventNestsLoop(void *message) {
const auto code = static_cast<const MSG*>(message)->message;
if (code > WM_NULL && code <= WM_GETMINMAXINFO) {
return true;
} else if (code >= WM_NCCREATE && code <= WM_NCXBUTTONDBLCLK) {
return true;
} else if (code == WM_WINDOWPOSCHANGING
|| code == WM_WINDOWPOSCHANGED
|| code == WM_STYLECHANGING
|| code == WM_STYLECHANGED) {
return true;
}
return false;
}
} // namespace Platform
void psNewVersion() {