diff --git a/src/load_save.c b/src/load_save.c index 4dc52ac0..18279984 100644 --- a/src/load_save.c +++ b/src/load_save.c @@ -256,6 +256,21 @@ load_save_load_game(Bygfoot *bygfoot, const gchar* filename, gboolean create_mai xml_loadsave_leagues_cups_read(bygfoot, dirname, prefix); + if(debug > 60) + g_print("load_save_load misc \n"); + + bygfoot_show_progress(bygfoot, + ((PROGRESS_MAX * bygfoot_get_progress_bar_fraction(bygfoot)) + 1) / PROGRESS_MAX, + _("Loading miscellaneous..."), + PIC_TYPE_LOAD); + + xml_loadsave_misc_read(bygfoot, dirname, prefix); + + /* Now that all the teams have been loaded, replace the team ids with team ptrs + * where necessary. */ + xml_loadsave_leagues_cups_adjust_team_ptrs(); + + if(debug > 60) g_print("load_save_load users \n"); @@ -307,16 +322,6 @@ load_save_load_game(Bygfoot *bygfoot, const gchar* filename, gboolean create_mai xml_loadsave_newspaper_read(dirname, prefix); - if(debug > 60) - g_print("load_save_load misc \n"); - - bygfoot_show_progress(bygfoot, - ((PROGRESS_MAX * bygfoot_get_progress_bar_fraction(bygfoot)) + 1) / PROGRESS_MAX, - _("Loading miscellaneous..."), - PIC_TYPE_LOAD); - - xml_loadsave_misc_read(bygfoot, dirname, prefix); - if(debug > 60) g_print("load_save_load done \n"); diff --git a/src/main.c b/src/main.c index e036fb9c..af3e65b8 100644 --- a/src/main.c +++ b/src/main.c @@ -288,6 +288,7 @@ main_init_variables(void) ligs = g_array_new(FALSE, FALSE, sizeof(League)); cps = g_array_new(FALSE, FALSE, sizeof(Cup));; acps = g_ptr_array_new(); + country_list = NULL; country.name = NULL; country.symbol = NULL; country.sid = NULL; diff --git a/src/xml_loadsave_leagues_cups.c b/src/xml_loadsave_leagues_cups.c index 901fe28c..92895a59 100644 --- a/src/xml_loadsave_leagues_cups.c +++ b/src/xml_loadsave_leagues_cups.c @@ -167,8 +167,6 @@ xml_loadsave_leagues_cups_read(Bygfoot *bygfoot, const gchar *dirname, const gch debug_print_message("xml_loadsave_misc_read: error parsing file %s\n", file); misc_print_error(&error, TRUE); } - - xml_loadsave_leagues_cups_adjust_team_ptrs(); } /** Write the leagues into xml files with the given prefix. */ diff --git a/src/xml_loadsave_misc.c b/src/xml_loadsave_misc.c index fd0ec418..e0c671b4 100644 --- a/src/xml_loadsave_misc.c +++ b/src/xml_loadsave_misc.c @@ -271,7 +271,8 @@ xml_loadsave_misc_read(Bygfoot *bygfoot, const gchar *dirname, const gchar *base g_ptr_array_free(acps, TRUE); acps = g_ptr_array_new(); - g_ptr_array_free(country_list, TRUE); + if (country_list) + g_ptr_array_free(country_list, TRUE); country_list = g_ptr_array_new(); free_bets(TRUE); diff --git a/test/test-load-save.sh b/test/test-load-save.sh index 8a10bf5d..f7506e9c 100644 --- a/test/test-load-save.sh +++ b/test/test-load-save.sh @@ -26,6 +26,7 @@ tmphome=`mktemp -d` pushd $bygfoot_bindir HOME=$tmphome ./bygfoot --random-seed=1 --json=$json_file +# Verify that the save file are identical. for f in save0 save1 save2 save3; do mkdir -p $save_dir/$f @@ -38,3 +39,13 @@ for f in save0 save1 save2 save3; do done diff -r $save_dir/save0 $save_dir/save1 diff -r $save_dir/save2 $save_dir/save3 + +# Test that we can load the saves on start up. +cat << EOF > $json_file +{ 'commands' : [ + {'load_bygfoot' : {'filename' : '$save_dir/save0.zip'}}, + {'load_bygfoot' : {'filename' : '$save_dir/save2.zip'}} +]} +EOF + +HOME=$tmphome ./bygfoot --random-seed=1 --json=$json_file