-
-
Notifications
You must be signed in to change notification settings - Fork 10.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Backends: Win32: Uninitialized context crash fix #6275
Conversation
Ignoring the window procedure handler for contexts that havn't been initialized yet will prevent this from crashing when the backend data is being accessed, for example on line 526. In my situation contexts(2) are being created before the window. Then when the window is created and starts sending messages i havn't had a chance yet to initialize each context. I'm thinking this early out will just discard messages for such contexts, similar to as-if there isn't an active context yet.
I believe this is the same as #6222 (specific comment linked). |
I dont think it's really similar, as this code already protects itself from 'misuse'. it just doesn't fully cover it. It checks against context being available, but not against context being valid. Design wise this check not being there i would have to go from:
to
It'll work, but hooking up with event dispatch in update rather than constructor is not as nice. |
It seems a little odd that you don't init backend at the same spot you create the imgui context, what is the reason for doing that? |
…ndProcHandler() with no active context! (#6275) Better standardized similar checks in other backends.
Been meaning to settle this as it is a low-hanging fruit,
I actually agree. For the record the check was added in dd89c9e (#1565) but I don't have enough details about the context. I don't like it too much and removed it now d15574c, I also standardized some similar checks for other backends. It strikes me as odd that the Win32 backend was the only backend with such a check. I added a specific comment near the assert to facilitate it if anyone stumbles on this.
For this specific matter, the crashing would happen immediately in your dev environment (aka it wouldn't be a "only crash in some setups/instances or for some users" crash) therefore it seems saner that you catch it.
It seems like the only notable difference is adding that same one-line check before your call to Sorry to be bike-shedding about such a minor thing but code calling that stuff some lives for decades and I'd rather enforce user-correct code. If I notice that d15574c causes trouble to too many people I might revert to honor legacy of this quirk. |
🤦♂️ facepalm, i was so busy tweaking the comments/asserts for other backends that I didn't realize d15574c broke our example, and gives us the answer as this extra check that existed since dd89c9e: win32 api CreateWindow does immediately calls WndProc. While it is perfectly possible to add an extra check in app/example custom WndProc handler before forwarding to I however added (in previous commit) the missing assert that will trigger if context exists but backend is not initialized, encouraging you to add an extra check |
👍 no worries here, it's good to clean up old stuff. Sorry to have stirred this up to become a breaking change for something so silly. The new assert clearly communicates that the responsibility is on the application and tells it what's required for it to work. |
+ fixed inconsistent use of break vs return 0 in WndProcHandler (had no tangible effect).
Plot twist, I have reverted my change and applied yours: ac90e1b What was happening before is that it was also easy to get in situation where WndProc was called BEFORE backend init but for messages we don't process, leading to no crash. Adding the assert exhibited those once harmless cases. Simply put I had an app in this situation, I realized I could fix it with an extra check, but checking "if backend is inited" is not going to be obvious for most users, so I decided it wasn't worth the hassle because of how Win32 setup is typically structured, and included your early out. Thank you! |
Ignoring the window procedure handler for contexts that havn't been initialized yet will prevent this from crashing when the backend data is being accessed, for example on line 526.
In my situation contexts(2) are being created before the window. Then when the window is created and starts sending messages i havn't had a chance yet to initialize each context. I'm thinking this early out will just discard messages for such contexts, similar to as-if there isn't an active context yet.