-
-
Notifications
You must be signed in to change notification settings - Fork 2.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
[rcore] InitWindow()
should check InitPlatform()
returned value
#4164
[rcore] InitWindow()
should check InitPlatform()
returned value
#4164
Conversation
`false` might be defined as `0` in `raylib.h`
src/rcore.c
Outdated
@@ -631,7 +631,12 @@ void InitWindow(int width, int height, const char *title) | |||
|
|||
// Initialize platform | |||
//-------------------------------------------------------------- | |||
InitPlatform(); | |||
if ( InitPlatform() != 0 ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I try to avoid this kind of structure on raylib, also, not following conventions, raylib does not place spaces between parenthesis. In any case it should be:
int result = InitPlatform();
if (result == -1) // Platform initialization failed
{
TRACELOG(LOG_WARNING, "WINDOW: Platform initialization failed");
//CORE.Window.ready = false; // If platform has not been correctly initialized, this should be already "false"
return; // In araylib I try to avoid/minimize early returns
}
@@ -476,15 +476,15 @@ int InitPlatform(void) | |||
if (platform.device == EGL_NO_DISPLAY) | |||
{ | |||
TRACELOG(LOG_WARNING, "DISPLAY: Failed to initialize EGL device"); | |||
return false; | |||
return -1; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, afaik, there is no clear convention defined on the function return values when used for errors detection... I tried to avoid that approach for raylib but I can consider it...
@SuperUserNameMan There is no clear convention on the function return values when used for errors detection... Actually, I tried to avoid that approach for most raylib functions (depite other libraries like SDL use it). I can consider it but it will require analyzing afected functions and conventions more carefully. For example, for All those questions require a review and redesign of the raylib library conventions and I prefer to consider them carefully. |
I did not want to touch `rcore.c`, but it was required for cross-paltform consistency, so that `SetMouseScale()` and `SetMouseOffset()` have same effect on every platform, and don't interfere with mouse offset and scaling required and preset by a platform which should, instead, use the new `CORE.Input.Mouse.platformOffset` and `CORE.Input.Mouse.platformScale`.
In case
PlatformInit()
fails,InitWindow()
should quit properly and setCORE.Window.ready = false
.Also fix
rcore_template.c
which returnedfalse
instead of-1
, asfalse
might be defined to0
inraylib.h
.Note that if the user forget to check
IsWindowReady()
before continuing, the program might still crash in a segfault ifInitPlatform()
failed.@raysan5 : could we change
void InitWindow()
tobool InitWindow()
instead of hoping the user think about checkingIsWindowReady()
in case ofInitPlatform()
failure ?