Added more error checking for SDL timer functions
This commit is contained in:
parent
99599d9236
commit
aaa9bf9422
1 changed files with 18 additions and 0 deletions
|
@ -279,6 +279,11 @@ static SDL_TimerID SDL_CreateTimer(Uint64 interval, SDL_TimerCallback callback_m
|
||||||
SDL_Timer *timer;
|
SDL_Timer *timer;
|
||||||
SDL_TimerMap *entry;
|
SDL_TimerMap *entry;
|
||||||
|
|
||||||
|
if (!callback_ms && !callback_ns) {
|
||||||
|
SDL_InvalidParamError("callback");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
SDL_LockSpinlock(&data->lock);
|
SDL_LockSpinlock(&data->lock);
|
||||||
if (!SDL_AtomicGet(&data->active)) {
|
if (!SDL_AtomicGet(&data->active)) {
|
||||||
if (SDL_InitTimers() < 0) {
|
if (SDL_InitTimers() < 0) {
|
||||||
|
@ -350,6 +355,10 @@ int SDL_RemoveTimer(SDL_TimerID id)
|
||||||
SDL_TimerMap *prev, *entry;
|
SDL_TimerMap *prev, *entry;
|
||||||
SDL_bool canceled = SDL_FALSE;
|
SDL_bool canceled = SDL_FALSE;
|
||||||
|
|
||||||
|
if (!id) {
|
||||||
|
return SDL_InvalidParamError("id");
|
||||||
|
}
|
||||||
|
|
||||||
/* Find the timer */
|
/* Find the timer */
|
||||||
SDL_LockMutex(data->timermap_lock);
|
SDL_LockMutex(data->timermap_lock);
|
||||||
prev = NULL;
|
prev = NULL;
|
||||||
|
@ -439,6 +448,11 @@ static SDL_TimerID SDL_CreateTimer(Uint64 interval, SDL_TimerCallback callback_m
|
||||||
SDL_TimerData *data = &SDL_timer_data;
|
SDL_TimerData *data = &SDL_timer_data;
|
||||||
SDL_TimerMap *entry;
|
SDL_TimerMap *entry;
|
||||||
|
|
||||||
|
if (!callback_ms && !callback_ns) {
|
||||||
|
SDL_InvalidParamError("callback");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
entry = (SDL_TimerMap *)SDL_malloc(sizeof(*entry));
|
entry = (SDL_TimerMap *)SDL_malloc(sizeof(*entry));
|
||||||
if (!entry) {
|
if (!entry) {
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -474,6 +488,10 @@ int SDL_RemoveTimer(SDL_TimerID id)
|
||||||
SDL_TimerData *data = &SDL_timer_data;
|
SDL_TimerData *data = &SDL_timer_data;
|
||||||
SDL_TimerMap *prev, *entry;
|
SDL_TimerMap *prev, *entry;
|
||||||
|
|
||||||
|
if (!id) {
|
||||||
|
return SDL_InvalidParamError("id");
|
||||||
|
}
|
||||||
|
|
||||||
/* Find the timer */
|
/* Find the timer */
|
||||||
prev = NULL;
|
prev = NULL;
|
||||||
for (entry = data->timermap; entry; prev = entry, entry = entry->next) {
|
for (entry = data->timermap; entry; prev = entry, entry = entry->next) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue