Skip to content
Browse files

made game to not segfault on attempt to switch to nonexistent state

but to crash instead
  • Loading branch information...
1 parent 173689b commit 84ba408207cfbad01eb782f3e9e02cce38135405 @niksaak committed Feb 21, 2013
Showing with 9 additions and 2 deletions.
  1. +9 −2 src/engine/stateman.c
View
11 src/engine/stateman.c
@@ -34,7 +34,7 @@ static state_t* find_state(const char* name)
} else if(!strcmp(name, list->node.name)) {
return list->node.state;
} else {
- return find_state(name);
+ return find(list->next);
}
}
@@ -92,5 +92,12 @@ state_t* curstate(void)
void swstate(const char* name)
{
- CurrentState = find_state(name);
+ state_t* new_state = find_state(name);
+
+ if(nullp(new_state))
+ CRASH("Can not switch to state %s because it does not exist", name);
+ if(!nullp(CurrentState))
+ CurrentState->sleep();
+ new_state->wake();
+ CurrentState = new_state;
}

0 comments on commit 84ba408

Please sign in to comment.
Something went wrong with that request. Please try again.