summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDarkvater <darkvater@openttd.org>2006-12-05 11:51:23 +0000
committerDarkvater <darkvater@openttd.org>2006-12-05 11:51:23 +0000
commit8904c04192cf2c2a4ee9f9b7743d21636daaadf9 (patch)
treef37fd443bf3aa8154c0c4c2b40e59af999f80348
parent4e26968521986b7cacfab849f13bef412cf705b7 (diff)
downloadopenttd-8904c04192cf2c2a4ee9f9b7743d21636daaadf9.tar.xz
(svn r7368) -Fix: [FS#332] Vehicle Deletion Crash [News Window Related?] (r3757).
-rw-r--r--news_gui.c14
1 files changed, 9 insertions, 5 deletions
diff --git a/news_gui.c b/news_gui.c
index 00b603047..feba825aa 100644
--- a/news_gui.c
+++ b/news_gui.c
@@ -253,6 +253,7 @@ void AddNewsItem(StringID string, uint32 flags, uint data_a, uint data_b)
{
NewsItem *ni;
Window *w;
+ byte l_news;
if (_game_mode == GM_MENU) return;
@@ -264,10 +265,11 @@ void AddNewsItem(StringID string, uint32 flags, uint data_a, uint data_b)
if (_total_news < MAX_NEWS) _total_news++;
// make sure our pointer isn't overflowing
+ l_news = _latest_news;
_latest_news = increaseIndex(_latest_news);
- // overwrite oldest news entry
- if (_oldest_news == _latest_news && _news_items[_oldest_news].string_id != 0)
+ /* If the fifo-buffer is full, overwrite the oldest entry */
+ if (l_news != INVALID_NEWS && _latest_news == _oldest_news)
_oldest_news = increaseIndex(_oldest_news); // but make sure we're not overflowing here
// add news to _latest_news
@@ -889,10 +891,12 @@ void DeleteVehicleNews(VehicleID vid, StringID news)
// If this is the last news item, invalidate _latest_news
if (_latest_news == _oldest_news) _latest_news = INVALID_NEWS;
- for (i = n; i != _oldest_news; i = (i + MAX_NEWS - 1) % MAX_NEWS) {
- _news_items[i] = _news_items[(i + MAX_NEWS - 1) % MAX_NEWS];
+ if (n != _oldest_news) {
+ for (i = n; i != _oldest_news; i = (i + MAX_NEWS - 1) % MAX_NEWS) {
+ _news_items[i] = _news_items[(i + MAX_NEWS - 1) % MAX_NEWS];
+ }
+ _oldest_news = increaseIndex(_oldest_news);
}
- _oldest_news = (_oldest_news + 1) % MAX_NEWS;
_total_news--;
w = FindWindowById(WC_MESSAGE_HISTORY, 0);