Skip to content

Commit a20d9de

Browse files
[desktop_glfw] fix InitPlatform crash caused by glfwCreateWindow... (#4804)
...returning NULL. This was causing a crash few lines later. Refs: #4801 (comment) Partially-fixes: #4801
1 parent eb8a343 commit a20d9de

File tree

1 file changed

+14
-12
lines changed

1 file changed

+14
-12
lines changed

src/platforms/rcore_desktop_glfw.c

+14-12
Original file line numberDiff line numberDiff line change
@@ -1521,6 +1521,12 @@ int InitPlatform(void)
15211521
SetupFramebuffer(CORE.Window.display.width, CORE.Window.display.height);
15221522

15231523
platform.handle = glfwCreateWindow(CORE.Window.display.width, CORE.Window.display.height, (CORE.Window.title != 0)? CORE.Window.title : " ", monitor, NULL);
1524+
if (!platform.handle)
1525+
{
1526+
glfwTerminate();
1527+
TRACELOG(LOG_WARNING, "GLFW: Failed to initialize Window");
1528+
return -1;
1529+
}
15241530

15251531
// NOTE: Full-screen change, not working properly...
15261532
//glfwSetWindowMonitor(platform.handle, glfwGetPrimaryMonitor(), 0, 0, CORE.Window.screen.width, CORE.Window.screen.height, GLFW_DONT_CARE);
@@ -1535,6 +1541,12 @@ int InitPlatform(void)
15351541
int creationHeight = CORE.Window.screen.height != 0 ? CORE.Window.screen.height : 1;
15361542

15371543
platform.handle = glfwCreateWindow(creationWidth, creationHeight, (CORE.Window.title != 0)? CORE.Window.title : " ", NULL, NULL);
1544+
if (!platform.handle)
1545+
{
1546+
glfwTerminate();
1547+
TRACELOG(LOG_WARNING, "GLFW: Failed to initialize Window");
1548+
return -1;
1549+
}
15381550

15391551
// After the window was created, determine the monitor that the window manager assigned.
15401552
// Derive display sizes, and, if possible, window size in case it was zero at beginning.
@@ -1558,18 +1570,8 @@ int InitPlatform(void)
15581570
return -1;
15591571
}
15601572

1561-
if (platform.handle)
1562-
{
1563-
CORE.Window.render.width = CORE.Window.screen.width;
1564-
CORE.Window.render.height = CORE.Window.screen.height;
1565-
}
1566-
}
1567-
1568-
if (!platform.handle)
1569-
{
1570-
glfwTerminate();
1571-
TRACELOG(LOG_WARNING, "GLFW: Failed to initialize Window");
1572-
return -1;
1573+
CORE.Window.render.width = CORE.Window.screen.width;
1574+
CORE.Window.render.height = CORE.Window.screen.height;
15731575
}
15741576

15751577
glfwMakeContextCurrent(platform.handle);

0 commit comments

Comments
 (0)