Add some error checking in Neverputt when loading SOLs
authorparasti <parasti@78b8d119-cf0a-0410-b17c-f493084dd1d7>
Sat, 4 Jun 2011 11:01:23 +0000 (11:01 +0000)
committerparasti <parasti@78b8d119-cf0a-0410-b17c-f493084dd1d7>
Sat, 4 Jun 2011 11:01:23 +0000 (11:01 +0000)
Do this so Putt would not crash on older format SOLs. Like me, players
probably have dozens of these installed through ZIP packages.

git-svn-id: https://s.snth.net/svn/neverball/branches/gles@3590 78b8d119-cf0a-0410-b17c-f493084dd1d7

putt/game.c
putt/game.h
putt/hole.c
putt/hole.h
putt/st_all.c

index e8f71d4..aef258b 100644 (file)
@@ -36,6 +36,8 @@
 static struct s_full file;
 static int           ball;
 
+static int state;
+
 static float view_a;                    /* Ideal view rotation about Y axis  */
 static float view_m;
 static float view_ry;                   /* Angular velocity about Y axis     */
@@ -83,7 +85,7 @@ static void view_init(void)
     view_e[2][2] = 1.f;
 }
 
-void game_init(const char *s)
+int game_init(const char *s)
 {
     int i;
 
@@ -93,7 +95,10 @@ void game_init(const char *s)
     idle_t = 1.0f;
 
     view_init();
-    sol_load_full(&file, s, config_get_d(CONFIG_SHADOW));
+
+    if (!(state = sol_load_full(&file, s, config_get_d(CONFIG_SHADOW))))
+        return 0;
+
     sol_init_sim(&file.vary);
 
     for (i = 0; i < file.base.dc; i++)
@@ -109,6 +114,7 @@ void game_init(const char *s)
                 idle_t = 1.0f;
         }
     }
+    return 1;
 }
 
 void game_free(void)
@@ -280,6 +286,9 @@ void game_draw(int pose, float t)
 
     float fov = FOV;
 
+    if (!state)
+        return;
+
     fp->shadow = ball;
 
     sol_draw_enable(&rend);
@@ -361,6 +370,9 @@ void game_update_view(float dt)
     float d[3];
     float s = 2.f * dt;
 
+    if (!state)
+        return;
+
     /* Center the view about the ball. */
 
     v_cpy(view_c, file.vary.uv[ball].p);
@@ -500,6 +512,9 @@ int game_step(const float g[3], float dt)
     float st = 0.f;
     int i, n = 1, m = 0;
 
+    if (!state)
+        return GAME_NONE;
+
     s = (7.f * s + dt) / 8.f;
     t = s;
 
@@ -596,6 +611,9 @@ void game_set_fly(float k)
     float p1[3] = { 0.f, 0.f, 0.f };
     float  v[3];
 
+    if (!state)
+        return;
+
     v_cpy(view_e[0], x);
     v_cpy(view_e[1], y);
     v_sub(view_e[2], fp->uv[ball].p, fp->base->zv[0].p);
index 47bc793..eae1cf6 100644 (file)
@@ -34,7 +34,7 @@
 
 /*---------------------------------------------------------------------------*/
 
-void  game_init(const char *);
+int   game_init(const char *);
 void  game_free(void);
 
 void  game_draw(int, float);
index af35b71..2d1e889 100644 (file)
@@ -218,7 +218,7 @@ const char *curr_par(void)
 
 /*---------------------------------------------------------------------------*/
 
-void hole_goto(int h, int p)
+int hole_goto(int h, int p)
 {
     int i;
 
@@ -227,20 +227,24 @@ void hole_goto(int h, int p)
         if (h >= 0) hole  = h;
         if (p >= 0) party = p;
 
-        player = (hole - 1) % party + 1;
-        done   = 0;
-
-        back_init(hole_v[hole].back);
-        game_init(hole_v[hole].file);
-
-        for (i = 1; i <= party; i++)
+        if (game_init(hole_v[hole].file))
         {
-            game_get_pos(ball_p[i], ball_e[i]);
-            stat_v[i] = 0;
+            back_init(hole_v[hole].back);
+
+            player = (hole - 1) % party + 1;
+            done   = 0;
+
+            for (i = 1; i <= party; i++)
+            {
+                game_get_pos(ball_p[i], ball_e[i]);
+                stat_v[i] = 0;
+            }
+            game_ball(player);
+            hole_song();
+            return 1;
         }
-        game_ball(player);
-        hole_song();
     }
+    return 0;
 }
 
 int hole_next(void)
@@ -270,9 +274,8 @@ int hole_move(void)
         game_free();
         back_free();
 
-        hole_goto(hole, party);
-
-        return 1;
+        if (hole_goto(hole, party))
+            return 1;
     }
     return 0;
 }
index 2063d53..0ef8b0c 100644 (file)
@@ -25,7 +25,7 @@ int  curr_count(void);
 const char *curr_scr(void);
 const char *curr_par(void);
 
-void hole_goto(int, int);
+int  hole_goto(int, int);
 int  hole_next(void);
 int  hole_move(void);
 void hole_goal(void);
index 15c35e2..9a29489 100644 (file)
@@ -453,23 +453,23 @@ static int party_action(int i)
     {
     case PARTY_1:
         audio_play(AUD_MENU, 1.f);
-        hole_goto(1, 1);
-        goto_state(&st_next);
+        if (hole_goto(1, 1))
+            goto_state(&st_next);
         break;
     case PARTY_2:
         audio_play(AUD_MENU, 1.f);
-        hole_goto(1, 2);
-        goto_state(&st_next);
+        if (hole_goto(1, 2))
+            goto_state(&st_next);
         break;
     case PARTY_3:
         audio_play(AUD_MENU, 1.f);
-        hole_goto(1, 3);
-        goto_state(&st_next);
+        if (hole_goto(1, 3))
+            goto_state(&st_next);
         break;
     case PARTY_4:
         audio_play(AUD_MENU, 1.f);
-        hole_goto(1, 4);
-        goto_state(&st_next);
+        if (hole_goto(1, 4))
+            goto_state(&st_next);
         break;
     case PARTY_B:
         audio_play(AUD_MENU, 1.f);
@@ -777,9 +777,8 @@ static int next_buttn(int b, int d)
     {
         if (config_tst_d(CONFIG_JOYSTICK_BUTTON_A, b))
         {
-            if (num > 0)
+            if (num > 0 && hole_goto(num, -1))
             {
-                hole_goto(num, -1);
                 num = 0;
                 return goto_state(&st_next);
             }