diff options
| author | iceyrazor <iceyrazor@mailfence.com> | 2026-02-24 20:58:44 -0600 |
|---|---|---|
| committer | iceyrazor <iceyrazor@mailfence.com> | 2026-02-24 20:58:44 -0600 |
| commit | 18dd286e09a443485dc749dddaa6fb3462033334 (patch) | |
| tree | 5115cbe89dabf3b9c32a8c318ff3919a42972a31 | |
| parent | b264506817f65660d57a7cdf24fcdef85a2f473e (diff) | |
fixed negative value crash
| -rwxr-xr-x | src/main.c | 26 |
1 files changed, 24 insertions, 2 deletions
@@ -1,3 +1,4 @@ +#include <SDL2/SDL_render.h> #include <SDL2/SDL_timer.h> #include <stdio.h> #include <stdbool.h> @@ -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); } |
