From a6805df42db79b51f132bcade8a196455bfebbce Mon Sep 17 00:00:00 2001 From: Allanis Date: Sun, 2 Jun 2013 13:57:00 +0100 Subject: [PATCH] [Fix] Segfault when trying to land on a system with no planets. --- src/opengl.h | 3 ++- src/player.c | 11 ++++++++--- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/opengl.h b/src/opengl.h index 1d5b4c6..22985f9 100644 --- a/src/opengl.h +++ b/src/opengl.h @@ -79,7 +79,8 @@ void gl_bindCamera(const Vec2* pos); // Circle drawing. void gl_drawCircle(const double x, const double y, const double r); void gl_drawCircleInRect(const double x, const double y, const double r, - const double rc, const double ry, const double rw, const double rh); + const double rc, const double ry, const double rw, + const double rh); // Initialize/cleanup. int gl_init(void); diff --git a/src/player.c b/src/player.c index aaa41d6..1b63d35 100644 --- a/src/player.c +++ b/src/player.c @@ -1178,6 +1178,10 @@ void player_targetPlanet(void) { // Attempt to land or target closest planet if no land target. void player_land(void) { + int i; + int tp; + double td, d; + if(landed) { // Player is already landed. takeoff(); @@ -1211,9 +1215,10 @@ void player_land(void) { land(planet); // Land the player. } else { // Get nearest planet target. - int i; - int tp; - double td, d; + if(cur_system->nplanets == 0) { + player_message("There are no planets to land on."); + return; + } td = -1; // Temp distance. tp = -1; // Temp planet.