-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
[rcore] InitWindow()
can cause a crash when Window and/or OpenGL context failed to initialize / IsWindowReady()
always returns true, meaning there is no way to recover
#4801
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
Comments
IsWindowReady()
does not return false when Window and/or OpenGL context failed to initialize, which can cause crashes without possibility to recoverInitWindow()
can cause a crash when Window and/or OpenGL context failed to initialize / IsWindowReady()
always returns true, meaning there is no way to recover
Agree that avoiding the crash would be a better alternative. Could the process (window+context creation) be validated to avoid the crash and just show a TraceLog() message with the issue (like most raylib functions approach) and then just set |
AFAIK: rcore_desktop_glfw InitPlatform() already does a lot of heavy lifting and validates some of window+context creation (e.g. here) but InitWindow() simply ignores any return values from InitPlatform (here). So doing what you have proposed shouldn't be a problem. We just need to make sure that all cases are handled and that other back-ends (SDL, RGFW, etc) do the same. I'll try to mess with this when I have some spare time (maybe even today). |
@sleeptightAnsiC Yeah, probably |
This comment has been minimized.
This comment has been minimized.
Case 3 is impossible to fix on Raylib's side (I think). It seems like an internal issue in Emscripten's GLFW port. Crash happens inside of java script when calling glfwInit(). |
Check the result of InitPlatform(), if it isn't 0, report the Error and return. This prevent crashes and allows for gracefully aborting or recovering by checking IsWindowReady(). Partially-fixes: raysan5#4801
...returning NULL. This was causing a crash few lines later. Refs: raysan5#4801 (comment) Partially-fixes: raysan5#4801
...returning NULL. This was causing a crash few lines later. Refs: raysan5#4801 (comment) Partially-fixes: raysan5#4801
This comment has been minimized.
This comment has been minimized.
…4804) ...returning NULL. This was causing a crash few lines later. Refs: #4801 (comment) Partially-fixes: #4801
This comment has been minimized.
This comment has been minimized.
@sleeptightAnsiC oh, it was closed on PR merge.. |
I think I am being a bit off-topic here, but one question nags at me. Who is the log message intended to benefit in a distributed raylib app? And if so, how are they expected to know about and find it? |
…orm (#4803) * [rcore] fix crash in InitWindow, due to unchecked result of InitPlatform Check the result of InitPlatform(), if it isn't 0, report the Error and return. This prevent crashes and allows for gracefully aborting or recovering by checking IsWindowReady(). Partially-fixes: #4801 * [rcore] style: store the result of InitPlatform() before checking it Small style change that doesn't impact how the code behaves here. Variable 'result' is not used anywhere else in this block, it's just for compliance with Raylib's coding conventions. Requested in PR: #4803 (comment) * [rcore] use LOG_WARNING when InitPlatform() fails ...as this is preferred over LOG_ERROR. Requested-by: #4803 (comment)
@raysan5 another reopen, pretty please 🙏
This issue is not about how to provide logging/errors to the end-user of the application. It's about recovering from the state, in which, developer MAY provide some information to the end-user (and abort/recover gracefully), but this is up to the developer to decide how to do it. There are many ways. You can predefined custom Before those patches I made, application would just crash, you would not be able to detect that something is wrong with I hope this answers your question? If not, let me know. Maybe I'm misunderstanding something here. |
I appreciate that the idea is not to crash and to find an alternative way to gracefully handle the particular situation. However, the code does rely on a raylib-established (?) macro and basically punts, without any indication that this is not helpful in an end-user situation. I can't imagine the above-proposed contortions being evident to those training on raylib. The preference for "warning" is also puzzling. |
@orcmid I don't think I understand the problem. I think, we may have a different poin-view on what is being discussed here.
I'm open to any suggestions. I agree the message in the warning might be too generic. I mentioned this in PR that failures in InitPlatform/InitWindow are very generic. Also, if InitPlatform ever fails, some other warnings should lead to it, coming from backend (see details for Case1 and Case2 in the report) and any trainee should be able to google them.
I wanted this to be an LOG_ERROR when I submitted PR #4803 (comment) but I honestly don't mind. |
Uh oh!
There was an error while loading. Please reload this page.
First mentioned here #4798 (comment) :
Given following code:
and compiled as follows:
$ git clone https://github.com/raysan5/raylib.git $ cd raylib/src $ make RAYLIB_BUILD_MODE=DEBUG $ cc main.c -o main -O0 -g -I. -L. -lraylib -lm -lGL $ ./main
I expect that this program will exit with error code 1, if InitWindow() failed to initialize Window/OpenGL context. This is exactly what note about IsWindowReady() suggests.
However, this is not what is happening right now. Application simply crashes, either somewhere inside of InitWindow() or somewhere later during main loop. There are multiple cases where this can happen (please, click at them in order to see the details):
[ Case 1: old GPU trying to load newer OpenGL context ]
[ Case 2: trying to run inside of headless environment ]
[ Case 3: doing something freaky, like trying to run raylib in NodeJS (similar to Case 2) ]
Tested mainly on Linux with Xorg, but also spotted in the past on Windows11 without GPU acceleration, and on MacOSX running inside of VM.
Related to: #4164, #4751, #3332, #2873
The text was updated successfully, but these errors were encountered: