[Qt] Crash when showing autocomplete outside of screen

25 views
Skip to first unread message

dail8859

unread,
Jul 28, 2022, 7:35:04 PM7/28/22
to scintilla-interest
Apologies for not adding this issue to the SourceForge tracker, I lost my login information.

If the cursor is outside of all desktop screens and autocomplete is attempted to be shown, it will crash the application. Reproduced on MacOS (Qt 5.15) and Win10 (Qt 5.15 and Qt 6.2)

In PlatQt.cpp: in QGuiApplication::screenAt() it is returning a null pointer if posGlobal is outside of any screen. 

The full call stack and details can be found on GitHub here: https://github.com/dail8859/NotepadNext/issues/184

Thanks,
Justin

Neil Hodgson

unread,
Jul 29, 2022, 12:08:48 AM7/29/22
to scintilla...@googlegroups.com
Justin:

> In PlatQt.cpp: in QGuiApplication::screenAt() it is returning a null pointer if posGlobal is outside of any screen.

Its likely there is a better approach but it should be possible to
avoid the crash by defaulting to the primary screen:

const QScreen *screen = QGuiApplication::screenAt(posGlobal);
if (!screen) {
screen = QGuiApplication::primaryScreen();
}

Neil

dail8859

unread,
Jul 30, 2022, 8:19:50 PM7/30/22
to scintilla-interest
Hi Neil,
As expected, that fixed the issue. I took a look to see if there was any API in Qt to provide the closest screen to the point (similar to how the Win32 platform does it) but doesn't seem to be anything readily available, so your solution at least prevents the crash. In theory the point could be off of a secondary screen, but for now I think this simple solution is the best solution.

Thanks,
Justin

Neil Hodgson

unread,
Aug 1, 2022, 2:19:24 AM8/1/22
to scintilla...@googlegroups.com
Committed with
https://sourceforge.net/p/scintilla/code/ci/91797711937039609a2944c75aa8bafe270bc6d2/

Also moved the window onto the screen when above it due to scrolling.
https://sourceforge.net/p/scintilla/code/ci/809b2900233af2cce8e82e65060eb2e111028ec0/

It may be an idea to scroll to the caret with SCI_SCROLLCARET
before showing the autocompletion on Qt.

Neil
Reply all
Reply to author
Forward
0 new messages