1
1
Fork 0
mirror of https://github.com/QB64-Phoenix-Edition/QB64pe.git synced 2024-07-22 20:45:13 +00:00
QB64-PE/internal/c
Matthew Kilgore d2aa572a94 Fix GLUT initialization logic
The current GLUT initialization logic is flawed because it allows the
QB64 code portion of the program to start on a separate thread at the
same time that the GLUT code is starting. This results in a race where
some commands won't work for a brief period at the beginning of the
program (with "won't work" being very inconsistent, some return invalid
values, some have a chance at seg faulting).

The same issue also leads to us adding many `while (!window_exists)`
checks in an attempt to solve this race for some of the commands.
Unfortunately this solution is very inconsistently applied leading to
some deadlock situations, and really it's a silly solution when this
race is entirely our creation anyway.

To fix this, the logic was changed such that we perform all of the GLUT
initialization besides calling `glutMainLoop()` before we ever start the
thread that runs the actual QB64 code. By doing it this way we ensure
that the GLUT initialization has already taken place before the code
runs and thus the race is gone.

Things get a bit more interesting with $SCREENHIDE, because that simply
delays the execution of the GLUT initialization indefinitely until
_ScreenShow is done. This was previously very buggy since some commands
rely on FreeGLUT being up and will simply hang the entire program if
run. Other commands have logic to catch this and simply return zero.

The above issue is solved with the `NEEDS_GLUT()` and `OPTIONAL_GLUT()`
macros. Both of them simply check if the GLUT initialization has taken
place and exit the current function if it has not. The difference
between the two is that `NEEDS_GLUT()` throws an 'illegal function call'
error while `OPTIONAL_GLUT()` simply exits with no error. The choice of
behavior of each function was based upon its previous behavior - if it
checked `screen_hide` and exited with no error previously, then
`OPTIONAL_GLUT()` was used. If it deadlocked or similar then
`NEEDS_GLUT()` was used (so instead of deadlocking, it now produces an
error). In this way, programs can now never get stuck due to the use of
`$SCREENHIDE` and all the commands have consistent behavior that can be
relied upon.

Fixes: #234
2022-11-26 01:33:32 -05:00
..
libqb Add _StatusCode command for HTTP handles 2022-11-20 04:04:02 -05:00
parts Add libqb_http API for HTTP connections 2022-11-19 15:13:26 -05:00
.gitignore setup_win.bat: create internal/c/c_compiler 2022-04-28 17:15:35 -04:00
common.h Include stdint.h on Windows, change integer defines to use them 2022-11-12 19:48:26 -05:00
libqb.cpp Fix GLUT initialization logic 2022-11-26 01:33:32 -05:00
libqb.h Fix common dialogs build.mk bug 2022-10-23 22:44:39 +05:30
libqb.mm (Automated push) Update internal/source/* from qb64.bas 2015-08-02 05:12:44 -07:00
msbin.c Format other various source files 2022-05-06 13:20:30 -04:00
mtri1.cpp Run clang-format on ./internal/c/*cpp files 2022-05-06 13:20:30 -04:00
mtri1s.cpp Run clang-format on ./internal/c/*cpp files 2022-05-06 13:20:30 -04:00
mtri1t.cpp Run clang-format on ./internal/c/*cpp files 2022-05-06 13:20:30 -04:00
mtri1ts.cpp Run clang-format on ./internal/c/*cpp files 2022-05-06 13:20:30 -04:00
mtri2.cpp Run clang-format on ./internal/c/*cpp files 2022-05-06 13:20:30 -04:00
mtri2s.cpp Run clang-format on ./internal/c/*cpp files 2022-05-06 13:20:30 -04:00
mtri2t.cpp Run clang-format on ./internal/c/*cpp files 2022-05-06 13:20:30 -04:00
mtri2ts.cpp Run clang-format on ./internal/c/*cpp files 2022-05-06 13:20:30 -04:00
mtri3.cpp Run clang-format on ./internal/c/*cpp files 2022-05-06 13:20:30 -04:00
mtri3s.cpp Run clang-format on ./internal/c/*cpp files 2022-05-06 13:20:30 -04:00
mtri3t.cpp Run clang-format on ./internal/c/*cpp files 2022-05-06 13:20:30 -04:00
mtri3ts.cpp Run clang-format on ./internal/c/*cpp files 2022-05-06 13:20:30 -04:00
mtri4.cpp Run clang-format on ./internal/c/*cpp files 2022-05-06 13:20:30 -04:00
mtri4s.cpp Run clang-format on ./internal/c/*cpp files 2022-05-06 13:20:30 -04:00
mtri4t.cpp Run clang-format on ./internal/c/*cpp files 2022-05-06 13:20:30 -04:00
mtri4ts.cpp Run clang-format on ./internal/c/*cpp files 2022-05-06 13:20:30 -04:00
myip.cpp Step 10: Update remaining stuff 2022-08-12 02:54:12 +02:00
os.h Include stdint.h on Windows, change integer defines to use them 2022-11-12 19:48:26 -05:00
purge_all_precompiled_content.bat Change purge scripts to use make clean 2022-05-19 09:17:13 -04:00
purge_all_precompiled_content.command Change purge scripts to use make clean 2022-05-19 09:17:13 -04:00
purge_all_precompiled_content.sh Change purge scripts to use make clean 2022-05-19 09:17:13 -04:00
qbx.cpp Fix GLUT initialization logic 2022-11-26 01:33:32 -05:00
time64.c Format other various source files 2022-05-06 13:20:30 -04:00
time64.h Format other various source files 2022-05-06 13:20:30 -04:00