mirror of
https://gitlab.com/dosowisko.net/libsuperderpy.git
synced 2025-02-07 21:56:44 +01:00
PrintConsole/DrawConsole: guard console data usage with mutexes
This commit is contained in:
parent
edb87bc2fc
commit
d8f975300d
4 changed files with 9 additions and 0 deletions
|
@ -195,6 +195,7 @@ SYMBOL_INTERNAL void DrawConsole(struct Game* game) {
|
|||
for (int i = 0; i < size; i++) {
|
||||
al_draw_filled_rectangle(0, 0, al_get_display_width(game->display), al_get_font_line_height(game->_priv.font_console) * (size - i), al_map_rgba(0, 0, 0, 80));
|
||||
}
|
||||
al_lock_mutex(game->_priv.mutex);
|
||||
int cur = game->_priv.console_pos + size;
|
||||
for (int i = 0; i < size; i++) {
|
||||
if (cur >= size) {
|
||||
|
@ -203,6 +204,7 @@ SYMBOL_INTERNAL void DrawConsole(struct Game* game) {
|
|||
al_draw_text(game->_priv.font_console, al_map_rgb(255, 255, 255), (int)(al_get_display_width(game->display) * 0.005), al_get_font_line_height(game->_priv.font_console) * i, ALLEGRO_ALIGN_LEFT, game->_priv.console[cur]);
|
||||
cur++;
|
||||
}
|
||||
al_unlock_mutex(game->_priv.mutex);
|
||||
|
||||
char sfps[16] = {0};
|
||||
snprintf(sfps, 6, "%.0f", game->_priv.fps_count.fps);
|
||||
|
|
|
@ -109,6 +109,8 @@ SYMBOL_EXPORT struct Game* libsuperderpy_init(int argc, char** argv, const char*
|
|||
game->_priv.bsod_cond = al_create_cond();
|
||||
game->_priv.bsod_mutex = al_create_mutex();
|
||||
|
||||
game->_priv.mutex = al_create_mutex();
|
||||
|
||||
game->config.fullscreen = strtol(GetConfigOptionDefault(game, "SuperDerpy", "fullscreen", "1"), NULL, 10);
|
||||
game->config.music = strtol(GetConfigOptionDefault(game, "SuperDerpy", "music", "10"), NULL, 10);
|
||||
game->config.voice = strtol(GetConfigOptionDefault(game, "SuperDerpy", "voice", "10"), NULL, 10);
|
||||
|
@ -497,6 +499,7 @@ SYMBOL_EXPORT void libsuperderpy_destroy(struct Game* game) {
|
|||
al_destroy_mutex(game->_priv.texture_sync_mutex);
|
||||
al_destroy_cond(game->_priv.bsod_cond);
|
||||
al_destroy_mutex(game->_priv.bsod_mutex);
|
||||
al_destroy_mutex(game->_priv.mutex);
|
||||
al_uninstall_audio();
|
||||
DeinitConfig(game);
|
||||
#ifndef __EMSCRIPTEN__
|
||||
|
|
|
@ -191,6 +191,8 @@ struct Game {
|
|||
ALLEGRO_MUTEX* bsod_mutex;
|
||||
ALLEGRO_COND* bsod_cond;
|
||||
|
||||
ALLEGRO_MUTEX* mutex;
|
||||
|
||||
struct {
|
||||
bool verbose, livereload, autopause;
|
||||
} debug;
|
||||
|
|
|
@ -417,6 +417,7 @@ SYMBOL_EXPORT char* GetDataFilePath(struct Game* game, const char* filename) {
|
|||
ALLEGRO_DEBUG_CHANNEL("libsuperderpy")
|
||||
|
||||
SYMBOL_EXPORT void PrintConsoleWithContext(struct Game* game, int line, const char* file, const char* func, char* format, ...) {
|
||||
al_lock_mutex(game->_priv.mutex);
|
||||
va_list vl;
|
||||
va_start(vl, format);
|
||||
char* text = game->_priv.console[game->_priv.console_pos];
|
||||
|
@ -444,6 +445,7 @@ SYMBOL_EXPORT void PrintConsoleWithContext(struct Game* game, int line, const ch
|
|||
if (game->_priv.console_pos >= (sizeof(game->_priv.console) / sizeof(game->_priv.console[0]))) {
|
||||
game->_priv.console_pos = 0;
|
||||
}
|
||||
al_unlock_mutex(game->_priv.mutex);
|
||||
}
|
||||
|
||||
SYMBOL_EXPORT void SetupViewport(struct Game* game, struct Viewport config) {
|
||||
|
|
Loading…
Reference in a new issue