From 8e7ab3b49b58ccdf07a2731cbe8c1340c6775606 Mon Sep 17 00:00:00 2001 From: Allen Webster Date: Wed, 25 Feb 2026 16:44:08 -0800 Subject: [PATCH] only enter main loop if initialization is successful --- wayland_xdg_egl.c | 56 ++++++++++++----------- x11_egl.c | 113 +++++++++++++++++++++++----------------------- 2 files changed, 85 insertions(+), 84 deletions(-) diff --git a/wayland_xdg_egl.c b/wayland_xdg_egl.c index baedba3..49ef4e3 100755 --- a/wayland_xdg_egl.c +++ b/wayland_xdg_egl.c @@ -514,33 +514,35 @@ int main(){ } /*~ NOTE: Main loop */ - int exit_loop = 0; - for (;!exit_loop;){ - /* (1) Appendix B: wl_display_dispatch_pending - ** " This function dispatches events on the main event queue. - ** ... it doesn't block." - */ - wl_display_dispatch_pending(ctx.wl_display); - - if (ctx.close_signal){ - exit_loop = 1; - } - - /*~ NOTE: render */ - { - glDrawBuffer(GL_BACK); - glViewport(0, 0, 640, 480); - glClearColor(0.40f, 0.90f, 0.15f, 1.f); - glClear(GL_COLOR_BUFFER_BIT); - } - - /* (egl) eglSwapBuffers - ** " back-buffered window surface, then the color buffer is copied - ** (posted) to the native window associated with that surface " - */ - EGLBoolean swap_success = eglSwapBuffers(ctx.egl_display, ctx.egl_surface); - if (!swap_success){ - printf("eglSwapBuffers failed\n"); + if (make_current_success2){ + int exit_loop = 0; + for (;!exit_loop;){ + /* (1) Appendix B: wl_display_dispatch_pending + ** " This function dispatches events on the main event queue. + ** ... it doesn't block." + */ + wl_display_dispatch_pending(ctx.wl_display); + + if (ctx.close_signal){ + exit_loop = 1; + } + + /*~ NOTE: render */ + { + glDrawBuffer(GL_BACK); + glViewport(0, 0, 640, 480); + glClearColor(0.40f, 0.90f, 0.15f, 1.f); + glClear(GL_COLOR_BUFFER_BIT); + } + + /* (egl) eglSwapBuffers + ** " back-buffered window surface, then the color buffer is copied + ** (posted) to the native window associated with that surface " + */ + EGLBoolean swap_success = eglSwapBuffers(ctx.egl_display, ctx.egl_surface); + if (!swap_success){ + printf("eglSwapBuffers failed\n"); + } } } diff --git a/x11_egl.c b/x11_egl.c index 1c690e9..c697e99 100755 --- a/x11_egl.c +++ b/x11_egl.c @@ -246,65 +246,64 @@ int main(int argc, char **argv){ } /*~ NOTE: Main loop */ - int exit_loop = 0; - if (!swap_interval_success){ - exit_loop = 1; - } - for (;!exit_loop;){ - - /* (1) /event-handling/XPending.html - ** " returns the number of events that have been received from the X - ** server but have not been removed from the event queue " - **~ NOTE: The docs say this returns the number of events, but it's - ** easier, and possibly more reliable to just use it to check if - ** there is at lesat one input. - */ - for (;XPending(display) > 0;){ - /* (1) /event-handling/manipulating-event-queue/XNextEvent.html - ** " copies the first event from the event queue into the specified - ** XEvent structure and then removes it from the queue " - */ - XEvent event; - XNextEvent(display, &event); + if (swap_interval_success){ + int exit_loop = 0; + for (;!exit_loop;){ - /* (1) /events/structures.html - ** " The XEvent structure is a union of the individual structures - ** declared for each event type. Depending on the type, you should - ** access members of each event by using the XEvent union. " - */ - switch (event.type){ - case ClientMessage: { - Atom atom = event.xclient.data.l[0]; - if (atom == atom__WM_DELETE_WINDOW){ - exit_loop = 1; - } - }break; + /* (1) /event-handling/XPending.html + ** " returns the number of events that have been received from the X + ** server but have not been removed from the event queue " + **~ NOTE: The docs say this returns the number of events, but it's + ** easier, and possibly more reliable to just use it to check if + ** there is at lesat one input. + */ + for (;XPending(display) > 0;){ + /* (1) /event-handling/manipulating-event-queue/XNextEvent.html + ** " copies the first event from the event queue into the specified + ** XEvent structure and then removes it from the queue " + */ + XEvent event; + XNextEvent(display, &event); + + /* (1) /events/structures.html + ** " The XEvent structure is a union of the individual structures + ** declared for each event type. Depending on the type, you should + ** access members of each event by using the XEvent union. " + */ + switch (event.type){ + case ClientMessage: { + Atom atom = event.xclient.data.l[0]; + if (atom == atom__WM_DELETE_WINDOW){ + exit_loop = 1; + } + }break; + } + } + + /* (1) /window-information/XGetWindowAttributes.html + ** " returns the current attributes for the specified window " + */ + XWindowAttributes window_attr = {0}; + if (!XGetWindowAttributes(display, window, &window_attr)){ + printf("XGetWindowAttributes failed\n"); + } + + /*~ NOTE: render */ + if (window_attr.width > 0 && window_attr.height > 0){ + glDrawBuffer(GL_BACK); + glViewport(0, 0, window_attr.width, window_attr.height); + glClearColor(0.90f, 0.15f, 0.40f, 1.f); + glClear(GL_COLOR_BUFFER_BIT); + } + + /* (2) eglSwapBuffers + ** " back-buffered window surface, then the color buffer is copied + ** (posted) to the native window associated with that surface " + */ + EGLBoolean swap_success = eglSwapBuffers(egl_display, surface); + if (!swap_success){ + printf("eglSwapBuffers failed\n"); } - } - - /* (1) /window-information/XGetWindowAttributes.html - ** " returns the current attributes for the specified window " - */ - XWindowAttributes window_attr = {0}; - if (!XGetWindowAttributes(display, window, &window_attr)){ - printf("XGetWindowAttributes failed\n"); - } - - /*~ NOTE: render */ - if (window_attr.width > 0 && window_attr.height > 0){ - glDrawBuffer(GL_BACK); - glViewport(0, 0, window_attr.width, window_attr.height); - glClearColor(0.90f, 0.15f, 0.40f, 1.f); - glClear(GL_COLOR_BUFFER_BIT); - } - - /* (2) eglSwapBuffers - ** " back-buffered window surface, then the color buffer is copied - ** (posted) to the native window associated with that surface " - */ - EGLBoolean swap_success = eglSwapBuffers(egl_display, surface); - if (!swap_success){ - printf("eglSwapBuffers failed\n"); } }