We are currently migrating Bugzilla to GitHub issues.
Any changes made to the bug tracker now will be lost, so please do not post new bugs or make changes to them.
When we're done, all bug URLs will redirect to their equivalent location on the new bug tracker.

Bug 2962

Summary: No error for negative SDL_Delay value
Product: SDL Reporter: lospenguins
Component: timerAssignee: Ryan C. Gordon <icculus>
Status: RESOLVED INVALID QA Contact: Sam Lantinga <slouken>
Severity: normal    
Priority: P2 CC: icculus
Version: 2.0.3   
Hardware: x86_64   
OS: Windows 8   

Description lospenguins 2015-04-26 02:49:25 UTC
I believe that SDL_Delay should not function the way it does when a negative value is passed. While it may seem silly, consider the following:


while (!quit) //tickrate is 15 in this example
{
                unsigned int ticks = SDL_GetTicks();

 		while ( SDL_PollEvent( &events_main ) != 0 )
                {
                    if ( events_main.type == SDL_QUIT )
                    {
                        quit = true;
                    }
                }

		SDL_RenderClear( renderer_main );

		//do stuff

		SDL_RenderPresent( renderer_main );

                int delay = tickrate - (SDL_GetTicks() - ticks);

		SDL_Delay( tickrate - (SDL_GetTicks() - ticks) );
	}
 

I had this in my main loop, and my program would only crash if I loaded an image while inside the loop. I figured out it was because loading an image took more than "tickrate - (SDL_GetTicks() - ticks)" milliseconds, so it would pass a negative value to SDL_Delay (which causes the program to hang). I wasted a good amount of time trying to figure out what I did, and thought it would save others time if SDL_Delay were to not accept negative values (either exit or convert the value to 0). I realize this "bug" is a result of me making an error, but I don't think someone making the same error I did should be penalized so heavily (without being told what went wrong).
Comment 1 Ryan C. Gordon 2015-04-27 04:15:07 UTC
SDL_Delay() takes an unsigned int for an argument, so you didn't pass it a negative value, you passed it a legitimate but extremely large value.

This isn't something we can change, sorry.

--ryan.