From 0087731ddb2b04171fe5c0ec5c295b9f2bd73b83 Mon Sep 17 00:00:00 2001 From: Celtic Minstrel Date: Sun, 13 Apr 2014 19:34:12 -0400 Subject: [PATCH] Fix crash when quitting the game --- osx/boe.dlgutil.cpp | 4 +--- osx/boe.infodlg.cpp | 4 +--- osx/boe.main.cpp | 4 +++- osx/boe.town.cpp | 3 +-- osx/tools/fileio.cpp | 19 ++++++++++++++----- osx/tools/fileio.h | 2 +- 6 files changed, 21 insertions(+), 15 deletions(-) diff --git a/osx/boe.dlgutil.cpp b/osx/boe.dlgutil.cpp index c027a7a0..d185ad6b 100644 --- a/osx/boe.dlgutil.cpp +++ b/osx/boe.dlgutil.cpp @@ -526,9 +526,7 @@ void start_talk_mode(short m_num,short personality,m_num_t monst_type,short stor // first make sure relevant talk strs are loaded in if (personality / 10 != univ.town.cur_talk_loaded){ - if(personality / 10 == univ.town.num) univ.town.cur_talk = &univ.town->talking; - else load_town(personality / 10,*univ.town.cur_talk); - univ.town.cur_talk_loaded = personality / 10; + load_town(personality / 10,univ.town.cur_talk); } // load all possible responses diff --git a/osx/boe.infodlg.cpp b/osx/boe.infodlg.cpp index fabe9632..696497b1 100644 --- a/osx/boe.infodlg.cpp +++ b/osx/boe.infodlg.cpp @@ -1050,9 +1050,7 @@ void put_talk(cDialog& me) if ((personality = univ.party.talk_save[store_page_on].personality) >= 0) { if (personality / 10 != univ.town.cur_talk_loaded){ - if(personality / 10 == univ.town.num) univ.town.cur_talk = &univ.town->talking; - else load_town(personality / 10,*univ.town.cur_talk); - univ.town.cur_talk_loaded = personality / 10; + load_town(personality / 10,univ.town.cur_talk); } // TODO: Use cached strings instead of loading them diff --git a/osx/boe.main.cpp b/osx/boe.main.cpp index 037e7025..08ff2eef 100644 --- a/osx/boe.main.cpp +++ b/osx/boe.main.cpp @@ -613,9 +613,11 @@ void Mouse_Pressed() void close_program() { + // TODO: Ultimately we would like to have cleanup happen automatically, negating the need for this function //end_music(); if(univ.town.loaded()) univ.town.unload(); - if(univ.town.cur_talk != NULL) delete univ.town.cur_talk; + if(univ.town.cur_talk_loaded != univ.town.num) + delete univ.town.cur_talk; clean_up_graphtool(); } diff --git a/osx/boe.town.cpp b/osx/boe.town.cpp index be2a92cd..0df7a831 100644 --- a/osx/boe.town.cpp +++ b/osx/boe.town.cpp @@ -178,8 +178,7 @@ void start_town_mode(short which_town, short entry_dir) load_town(town_number,univ.town.record); univ.town.num = town_number; - univ.town.cur_talk = &univ.town->talking; - univ.town.cur_talk_loaded = univ.town.num; + load_town(town_number,univ.town.cur_talk); init_town(); // if (play_town_sound == true) { diff --git a/osx/tools/fileio.cpp b/osx/tools/fileio.cpp index 563a8f8a..ab150661 100644 --- a/osx/tools/fileio.cpp +++ b/osx/tools/fileio.cpp @@ -334,7 +334,16 @@ bool load_town(short which_town, cTown*& the_town){ return true; } -bool load_town(short which_town, cSpeech& the_talk){ +bool load_town(short which_town, cSpeech*& the_talk){ + if(which_town == univ.town.cur_talk_loaded) return true; + if(univ.town.num != univ.town.cur_talk_loaded) delete the_talk; + univ.town.cur_talk_loaded = which_town; + if(which_town == univ.town.num) { + the_talk = &univ.town->talking; + return true; + } + the_talk = new cSpeech; + short i,n; long len,len_to_jump = 0; legacy::town_record_type store_town; @@ -399,12 +408,12 @@ bool load_town(short which_town, cSpeech& the_talk){ return false; } port_talk_nodes(&store_talk); - the_talk = store_talk; + *the_talk = store_talk; for (i = 0; i < 170; i++) { - len = (long) (the_talk.strlens[i]); - n = fread(&(the_talk.talk_strs[i]), len, 1, file_id); - the_talk.talk_strs[i][len] = 0; + len = (long) (the_talk->strlens[i]); + n = fread(&(the_talk->talk_strs[i]), len, 1, file_id); + the_talk->talk_strs[i][len] = 0; } // town_type = scenario.town_size[which_town]; diff --git a/osx/tools/fileio.h b/osx/tools/fileio.h index 39779b08..ee589a24 100644 --- a/osx/tools/fileio.h +++ b/osx/tools/fileio.h @@ -16,7 +16,7 @@ namespace fs = boost::filesystem; // TODO: Centralize this alias! bool load_scenario(fs::path file_to_load); bool load_town(short which_town, cTown*& the_town); -bool load_town(short which_town, cSpeech& the_talk); +bool load_town(short which_town, cSpeech*& the_talk); bool load_town_str(short which_town, short which_str, char* str); bool load_town_str(short which_town, cTown*& the_town); bool load_outdoors(location which_out,cOutdoors& the_out);