Skip to content
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

Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/platforms/rcore_template.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Copy link
Owner

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...

}

// Initialize the EGL device connection
if (eglInitialize(platform.device, NULL, NULL) == EGL_FALSE)
{
// If all of the calls to eglInitialize returned EGL_FALSE then an error has occurred.
TRACELOG(LOG_WARNING, "DISPLAY: Failed to initialize EGL device");
return false;
return -1;
}

// Get an appropriate EGL framebuffer configuration
Expand Down
7 changes: 6 additions & 1 deletion src/rcore.c
Original file line number Diff line number Diff line change
Expand Up @@ -631,7 +631,12 @@ void InitWindow(int width, int height, const char *title)

// Initialize platform
//--------------------------------------------------------------
InitPlatform();
if ( InitPlatform() != 0 )
Copy link
Owner

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
}

{
TRACELOG(LOG_ERROR, "Platform backend: Window initialization failed.");
CORE.Window.ready = false;
return;
}
//--------------------------------------------------------------

// Initialize rlgl default data (buffers and shaders)
Expand Down
Loading