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 - No error for negative SDL_Delay value
Summary: No error for negative SDL_Delay value
Status: RESOLVED INVALID
Alias: None
Product: SDL
Classification: Unclassified
Component: timer (show other bugs)
Version: 2.0.3
Hardware: x86_64 Windows 8
: P2 normal
Assignee: Ryan C. Gordon
QA Contact: Sam Lantinga
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2015-04-26 02:49 UTC by lospenguins
Modified: 2015-04-27 04:15 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
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.