Win32: a failed RegisterClassW or CreateWindowExW shows a MessageBox and the constructor carries on with a null HWND #209
Labels
No labels
claude:blocked
claude:done
claude:failed
claude:in-progress
claude:ready
bug
duplicate
enhancement
help wanted
invalid
question
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
Catcrafts/Crafter.Graphics#209
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Summary
The Win32 constructor reports a failed window class registration and a failed
CreateWindowExWwith a modalMessageBoxand carries on: it shows and updates a nullhwndand passes it tovkCreateWin32SurfaceKHR, whose valid usage asks for a validHWND. It should throw at the failed step, which sincee1ca2fd(#169) also releases what it had made. Line numbers refer toe1ca2fd.Details
implementations/Crafter.Graphics-Window.cpp:448-449:if (!RegisterClassW(&wc) && GetLastError() != ERROR_CLASS_ALREADY_EXISTS)showsMessageBox(NULL, "Window Class Registration Failed!", ...), and the constructor goes on toCreateWindowExWwith that class (:455).:467-468:if (hwnd == NULL)showsMessageBox(NULL, "Window Creation Failed!", ...), and the constructor goes on toShowWindow(hwnd, SW_SHOWNORMAL)andUpdateWindow(hwnd)(:472-473), the message pump, andcreateInfo.hwnd = hwnd;intovkCreateWin32SurfaceKHR(:488-489).chapters/VK_KHR_surface/wsi.adoc:350-351at Vulkan-Docsv1.4.369: "hwnd must be a valid Win32 HWND". With a null one the outcome is the driver's: an error, whichCheckVkResultthrows and~Windownow cleans up after, or anything else.charstrings toMessageBox, the A function (#186).Found by reading the code, in the pre-push review of #169's fix; not reproduced.
Suggested fix
Throw a
std::runtime_errornaming the call andGetLastError()whereRegisterClassWfails with anything butERROR_CLASS_ALREADY_EXISTSand whereCreateWindowExWreturns null, and drop the twoMessageBoxcalls. Since #169's fix the constructor delegates toWindow(), so~Windowthen releases what had been made; it skips a nullhwnd.