Commit: 6d2a961ffa4e57e0e05fdcffa358eda7f3fb2104
Parent: 4538824e7f82b74c034871c95789037be6b20193
Author: Randy Palamar
Date: Mon, 10 Jun 2024 19:04:03 -0600
avoid race condition and buggy glibc codepath in debug
Diffstat:
1 file changed, 10 insertions(+), 3 deletions(-)
diff --git a/main.c b/main.c
@@ -4,6 +4,7 @@
#include <raylib.h>
#include <stdio.h>
#include <sys/stat.h>
+#include <unistd.h>
#include "util.c"
@@ -36,11 +37,16 @@ compare_filetime(Filetime a, Filetime b)
static void
load_library(const char *lib)
{
- dlclose(libhandle);
+ /* NOTE: glibc is buggy gnuware so we need to check this */
+ if (libhandle)
+ dlclose(libhandle);
libhandle = dlopen(lib, RTLD_NOW|RTLD_LOCAL);
+ if (!libhandle)
+ fprintf(stderr, "do_debug: dlopen: %s\n", dlerror());
+
do_colour_picker = dlsym(libhandle, "do_colour_picker");
- if (!libhandle || !do_colour_picker)
- fprintf(stderr, "Couldn't Hot Reload ColourPicker\n");
+ if (!do_colour_picker)
+ fprintf(stderr, "do_debug: dlsym: %s\n", dlerror());
}
static void
@@ -49,6 +55,7 @@ do_debug(void)
static Filetime updated_time;
Filetime test_time = get_filetime(libname);
if (compare_filetime(test_time, updated_time)) {
+ sync();
load_library(libname);
updated_time = test_time;
}