mirror of
https://github.com/lov3b/Pong.git
synced 2025-01-18 04:30:11 +01:00
nullptr error handling
This commit is contained in:
parent
de58a7f405
commit
2f401e8d32
10
src/Game.cpp
10
src/Game.cpp
@ -47,6 +47,11 @@ void Game::draw(SDL_Renderer *const renderer) {
|
||||
void Game::update() {
|
||||
switch (gameState) {
|
||||
case GameState::START_SCREEN:
|
||||
// This should not happen, but it's better than a segfault.
|
||||
if (startScreen == nullptr) {
|
||||
std::cerr << "startScreen was not initialized (null)." << std::endl;
|
||||
exit(-1);
|
||||
}
|
||||
startScreen->update();
|
||||
if (startScreen->isDone()) {
|
||||
gameState = GameState::GAME;
|
||||
@ -71,6 +76,11 @@ void Game::update() {
|
||||
}
|
||||
break;
|
||||
case GameState::END_SCREEN:
|
||||
// This should not happen, but it's better than a segfault.
|
||||
if (endScreen == nullptr) {
|
||||
std::cerr << "endScreen was not initialized (null)." << std::endl;
|
||||
exit(-1);
|
||||
}
|
||||
endScreen->update();
|
||||
if (endScreen->isDone()) {
|
||||
gameState = GameState::GAME;
|
||||
|
Loading…
x
Reference in New Issue
Block a user