From 18dd286e09a443485dc749dddaa6fb3462033334 Mon Sep 17 00:00:00 2001 From: iceyrazor Date: Tue, 24 Feb 2026 20:58:44 -0600 Subject: fixed negative value crash --- src/main.c | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/src/main.c b/src/main.c index c5439e5..e863001 100755 --- a/src/main.c +++ b/src/main.c @@ -1,3 +1,4 @@ +#include #include #include #include @@ -64,6 +65,7 @@ int main(int argc, char *argv[]) SDL_SetRenderDrawBlendMode(renderer, SDL_BLENDMODE_BLEND); bool quit = false; + bool window_visible; Uint32 lastUpdate = 0; SDL_Event e; while (!quit) { @@ -78,7 +80,19 @@ int main(int argc, char *argv[]) } } else if(e.type==SDL_MOUSEBUTTONUP){ stuff.mousedown=false; - } + } else if (e.type == SDL_WINDOWEVENT) { + if (e.window.event == SDL_WINDOWEVENT_MINIMIZED || + e.window.event == SDL_WINDOWEVENT_HIDDEN) { + + window_visible = false; + } + else if (e.window.event == SDL_WINDOWEVENT_SHOWN || + e.window.event == SDL_WINDOWEVENT_RESTORED || + e.window.event == SDL_WINDOWEVENT_FOCUS_GAINED) { + + window_visible = true; + } + } stuff.mx=e.button.x; stuff.my=e.button.y; } @@ -89,6 +103,10 @@ int main(int argc, char *argv[]) mutVolume.locked=false; } + if(!window_visible){ + SDL_Delay(50); + continue; + } Uint64 start = SDL_GetPerformanceCounter(); //SDL_Log("vol: %f avg: %f",stuff.volume,stuff.avg_peak); Uint32 current=SDL_GetTicks(); @@ -98,7 +116,11 @@ int main(int argc, char *argv[]) Uint64 end = SDL_GetPerformanceCounter(); float elapsedMS = (end - start) / (float)SDL_GetPerformanceFrequency() * 1000.0f; - SDL_Delay(floor(16.666f - elapsedMS)); + + elapsedMS=floor(16.666f - elapsedMS); + if (elapsedMS > 500) elapsedMS=500; + if (elapsedMS < 0) elapsedMS=0; + SDL_Delay(elapsedMS); //SDL_Delay(rand() % 25); } -- cgit v1.3