Repository navigation
Conversation
When WM_NCCREATE or WM_CREATE failed, the error was only logged, and create_window returned Error::from_thread(), which is just whatever the thread's last error happened to be. Keep the error in WindowData and return it from create_window, falling back to GetLastError only when CreateWindowExW failed on its own. create_window now returns PlatformError, so TimerList follows.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
I ran into this while testing a vizia change that makes a failed
open_parentedreturn an error instead of only logging it. On macOS the error that came back was the real reason, but on Windows it was some leftoverGetLastErrorvalue:0x80070002once and0another time. baseview only sends the actual reason to the log, and only with thetracingfeature on.What happens: when
WM_NCCREATEorWM_CREATEfails (say the GL context can't be created, or the window handler builder returns an error),handle_error_as_fatallogs the error and the window proc fails the message, soCreateWindowExWreturns NULL.create_windowthen returnsError::from_thread(), but nothing in that path sets the thread's last error to the actual failure, so you get whatever happens to be there.The fix:
WindowDatagets a slot for that error.handle_error_as_fatalstill logs it, then puts it in the slot before dropping the window's reference to the data, andcreate_windowreturns it whenCreateWindowExWgives back NULL.create_windowholds its ownRcto the data, so it's still there to read. If the slot is empty, none of our steps failed, soCreateWindowExWfailed on its own (a bad parent, say), and in that caseGetLastErrordoes mean something, so it still falls back toError::from_thread().Since
create_windownow returns aPlatformErrorinstead of awindows_core::Error, the timer window code that also calls it (TimerList) returnsPlatformResultas well, andcreate_timerdrops anOk(...?).Tests: I added two Windows tests in
src/platform/win/tests.rs. The first creates a window whose handler builder returns an error, and checks that the error coming out ofWindow::createhas that same error as its source. It fails on master. The second creates a child window inside a parent that's already been destroyed, soCreateWindowExWfails on its own, and checks the error is stillERROR_INVALID_WINDOW_HANDLEfrom the fallback.