mirror of
https://github.com/lov3b/Pong.git
synced 2025-01-18 12:40:12 +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() {
|
void Game::update() {
|
||||||
switch (gameState) {
|
switch (gameState) {
|
||||||
case GameState::START_SCREEN:
|
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();
|
startScreen->update();
|
||||||
if (startScreen->isDone()) {
|
if (startScreen->isDone()) {
|
||||||
gameState = GameState::GAME;
|
gameState = GameState::GAME;
|
||||||
@ -71,6 +76,11 @@ void Game::update() {
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case GameState::END_SCREEN:
|
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();
|
endScreen->update();
|
||||||
if (endScreen->isDone()) {
|
if (endScreen->isDone()) {
|
||||||
gameState = GameState::GAME;
|
gameState = GameState::GAME;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user