From 267431346b3a80bdd6ef030dffebf7892fdd73a6 Mon Sep 17 00:00:00 2001 From: zuu Date: Sun, 21 Jul 2013 15:21:55 +0000 Subject: [PATCH] (svn r25621) -Fix (r25342): Also delete page elments when their page is removed (so that they don't reappear on a new page later on) --- src/story_base.h | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/story_base.h b/src/story_base.h index d295671f14..3db1ba4a86 100644 --- a/src/story_base.h +++ b/src/story_base.h @@ -63,6 +63,9 @@ struct StoryPageElement : StoryPageElementPool::PoolItem<&_story_page_element_po inline ~StoryPageElement() { free(this->text); } }; +#define FOR_ALL_STORY_PAGE_ELEMENTS_FROM(var, start) FOR_ALL_ITEMS_FROM(StoryPageElement, story_page_element_index, var, start) +#define FOR_ALL_STORY_PAGE_ELEMENTS(var) FOR_ALL_STORY_PAGE_ELEMENTS_FROM(var, 0) + /** Struct about stories, current and completed */ struct StoryPage : StoryPagePool::PoolItem<&_story_page_pool> { uint32 sort_value; ///< A number that increases for every created story page. Used for sorting. The id of a story page is the pool index. @@ -79,11 +82,18 @@ struct StoryPage : StoryPagePool::PoolItem<&_story_page_pool> { /** * (Empty) destructor has to be defined else operator delete might be called with NULL parameter */ - inline ~StoryPage() { free(this->title); } + inline ~StoryPage() + { + if (!this->CleaningPool()) { + StoryPageElement *spe; + FOR_ALL_STORY_PAGE_ELEMENTS(spe) { + if (spe->page == this->index) delete spe; + } + } + free(this->title); + } }; -#define FOR_ALL_STORY_PAGE_ELEMENTS_FROM(var, start) FOR_ALL_ITEMS_FROM(StoryPageElement, story_page_element_index, var, start) -#define FOR_ALL_STORY_PAGE_ELEMENTS(var) FOR_ALL_STORY_PAGE_ELEMENTS_FROM(var, 0) #define FOR_ALL_STORY_PAGES_FROM(var, start) FOR_ALL_ITEMS_FROM(StoryPage, story_page_index, var, start) #define FOR_ALL_STORY_PAGES(var) FOR_ALL_STORY_PAGES_FROM(var, 0)