From 87697965c97dc0131ef7085b00040f1308cf824f Mon Sep 17 00:00:00 2001 From: Cong Date: Wed, 3 Jul 2013 20:07:42 +1000 Subject: [PATCH] Config reverts if apply failed (fixes #116) --- src/cdogs/config.h | 2 +- src/cdogs/config_apply.c | 3 ++- src/menu.c | 12 +++++++++++- 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/src/cdogs/config.h b/src/cdogs/config.h index f8fd7d737..95ec56eba 100644 --- a/src/cdogs/config.h +++ b/src/cdogs/config.h @@ -91,7 +91,7 @@ extern Config gConfig; void ConfigLoad(Config *config, const char *filename); void ConfigSave(Config *config, const char *filename); -void ConfigApply(Config *config); +int ConfigApply(Config *config); void ConfigLoadDefault(Config *config); int ConfigGetVersion(FILE *f); diff --git a/src/cdogs/config_apply.c b/src/cdogs/config_apply.c index 903a3596f..634ccd3d2 100644 --- a/src/cdogs/config_apply.c +++ b/src/cdogs/config_apply.c @@ -32,10 +32,11 @@ #include "gamedata.h" -void ConfigApply(Config *config) +int ConfigApply(Config *config) { BlitSetBrightness(config->Graphics.Brightness); SoundReconfigure(&gSoundDevice, &config->Sound); gCampaign.seed = config->Game.RandomSeed; GraphicsInitialize(&gGraphicsDevice, &config->Graphics, 0); + return gGraphicsDevice.IsInitialized; } diff --git a/src/menu.c b/src/menu.c index 9bbd0055a..2f25a7ee8 100644 --- a/src/menu.c +++ b/src/menu.c @@ -799,6 +799,7 @@ void MenuChangeIndex(menu_t *menu, int cmd) void MenuActivate(menu_t *menu, int cmd) { + Config lastConfig = gConfig; SoundPlay(&gSoundDevice, SND_SWITCH); switch (menu->type) { @@ -927,5 +928,14 @@ void MenuActivate(menu_t *menu, int cmd) assert(0); break; } - ConfigApply(&gConfig); + if (!ConfigApply(&gConfig)) + { + printf("Error: cannot apply new config; applying last config\n"); + gConfig = lastConfig; + if (!ConfigApply(&gConfig)) + { + printf("Error: cannot apply last config!\n"); + exit(1); + } + } }