summaryrefslogtreecommitdiff
path: root/src/news_gui.cpp
diff options
context:
space:
mode:
authorrubidium <rubidium@openttd.org>2010-12-10 22:39:01 +0000
committerrubidium <rubidium@openttd.org>2010-12-10 22:39:01 +0000
commit676a53fb407896d0a6c3fc0a687a6280338e7acb (patch)
tree8281cd602f68bc78fa5369ce4bb6f9d1da33aebe /src/news_gui.cpp
parent8faa97c060e2bec58c8e0dd41f9af40af3a15412 (diff)
downloadopenttd-676a53fb407896d0a6c3fc0a687a6280338e7acb.tar.xz
(svn r21458) -Fix [FS#4180]: possible crash when news item gets removed at just the wrong moment
Diffstat (limited to 'src/news_gui.cpp')
-rw-r--r--src/news_gui.cpp21
1 files changed, 12 insertions, 9 deletions
diff --git a/src/news_gui.cpp b/src/news_gui.cpp
index e848f3dd5..1a2997944 100644
--- a/src/news_gui.cpp
+++ b/src/news_gui.cpp
@@ -722,14 +722,7 @@ void AddNewsItem(StringID string, NewsSubtype subtype, NewsReferenceType reftype
/** Delete a news item from the queue */
static void DeleteNewsItem(NewsItem *ni)
{
- if (_forced_news == ni || _current_news == ni) {
- /* about to remove the currently forced item (shown as newspapers) ||
- * about to remove the currently displayed item (newspapers, ticker, or just a reminder) */
- MoveToNextItem();
- }
-
- /* delete item */
-
+ /* Delete the news from the news queue. */
if (ni->prev != NULL) {
ni->prev->next = ni->next;
} else {
@@ -744,8 +737,18 @@ static void DeleteNewsItem(NewsItem *ni)
_latest_news = ni->prev;
}
- if (_current_news == ni) _current_news = ni->prev;
_total_news--;
+
+ if (_forced_news == ni || _current_news == ni || _statusbar_news_item == ni) {
+ /* When we're the current news, go to the previous item first;
+ * we just possibly made that the last news item. */
+ if (_current_news == ni) _current_news = ni->prev;
+
+ /* About to remove the currently forced item (shown as newspapers) ||
+ * about to remove the currently displayed item (newspapers, ticker, or just a reminder) */
+ MoveToNextItem();
+ }
+
delete ni;
SetWindowDirty(WC_MESSAGE_HISTORY, 0);