From 2c27f9851b723d3b7e6fe1847319baedc11216bf Mon Sep 17 00:00:00 2001 From: Maarten Bent Date: Mon, 2 Sep 2019 23:49:32 +0200 Subject: [PATCH] Check if window is created before getting the display it is on If it is not initialised, getting the screen rectangle will fail, so don't even try doing it, but just return wxNOT_FOUND instead, so the main display will be used -- this is the best we can do if the window hasn't been created yet, as we don't know on which display it will appear. Closes https://github.com/wxWidgets/wxWidgets/pull/1527 Closes #18481. --- src/common/dpycmn.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/common/dpycmn.cpp b/src/common/dpycmn.cpp index a73a8f423a..b9123f39dd 100644 --- a/src/common/dpycmn.cpp +++ b/src/common/dpycmn.cpp @@ -249,6 +249,13 @@ int wxDisplayFactory::GetFromWindow(const wxWindow *window) { wxCHECK_MSG( window, wxNOT_FOUND, "window can't be NULL" ); + // Check if the window is created: we can't find its display before this is + // done anyhow, as we simply don't know on which display will it appear, + // and trying to do this below would just result in assert failures inside + // GetScreenRect() if the window doesn't yet exist, so return immediately. + if ( !window->GetHandle() ) + return wxNOT_FOUND; + // consider that the window belongs to the display containing its centre const wxRect r(window->GetScreenRect()); return GetFromPoint(wxPoint(r.x + r.width/2, r.y + r.height/2));