summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorzuu <zuu@openttd.org>2013-07-21 15:21:55 +0000
committerzuu <zuu@openttd.org>2013-07-21 15:21:55 +0000
commit5ea7ab1ad232b0655ae24d6d4dfadc20acc870df (patch)
tree0a3a4a4caa5bb52ad5e5101cecde94744cfefbc8 /src
parent09897c5fd68668c148859314f5e6a1f64dd4634b (diff)
downloadopenttd-5ea7ab1ad232b0655ae24d6d4dfadc20acc870df.tar.xz
(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)
Diffstat (limited to 'src')
-rw-r--r--src/story_base.h16
1 files changed, 13 insertions, 3 deletions
diff --git a/src/story_base.h b/src/story_base.h
index d295671f1..3db1ba4a8 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)