From 0f0d9da839742701da4998a51ddc3850282e0530 Mon Sep 17 00:00:00 2001 From: Randy Heit Date: Thu, 29 Aug 2013 22:22:30 -0500 Subject: [PATCH] Reset FirstFreeEntry in ACSStringPool::ReadStrings() - Fixed: When an ACS string pool was read from a savegame, FirstFreeEntry would not be updatedt, except by the Clear() function. This left FirstFreeEntry at 0, which meant the next string added to the pool would always go in slot 0, whether it was free or not. --- src/p_acs.cpp | 25 ++++++++++++++++++++----- src/p_acs.h | 1 + 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/src/p_acs.cpp b/src/p_acs.cpp index b707f4444..32a70cd15 100644 --- a/src/p_acs.cpp +++ b/src/p_acs.cpp @@ -575,11 +575,7 @@ int ACSStringPool::InsertString(FString &str, unsigned int h, unsigned int bucke } else { // Scan for the next free entry - unsigned int i; - for (i = FirstFreeEntry + 1; i < Pool.Size() && Pool[i].Next != FREE_ENTRY; ++i) - { - } - FirstFreeEntry = i; + FindFirstFreeEntry(FirstFreeEntry + 1); } PoolEntry *entry = &Pool[index]; entry->Str = str; @@ -590,6 +586,23 @@ int ACSStringPool::InsertString(FString &str, unsigned int h, unsigned int bucke return index | STRPOOL_LIBRARYID_OR; } +//============================================================================ +// +// ACSStringPool :: FindFirstFreeEntry +// +// Finds the first free entry, starting at base. +// +//============================================================================ + +void ACSStringPool::FindFirstFreeEntry(unsigned base) +{ + while (base < Pool.Size() && Pool[base].Next != FREE_ENTRY) + { + base++; + } + FirstFreeEntry = base; +} + //============================================================================ // // ACSStringPool :: ReadStrings @@ -638,6 +651,7 @@ void ACSStringPool::ReadStrings(PNGHandle *png, DWORD id) { delete[] str; } + FindFirstFreeEntry(0); } } @@ -690,6 +704,7 @@ void ACSStringPool::Dump() const Printf("%4u. (%2d) \"%s\"\n", i, Pool[i].LockCount, Pool[i].Str.GetChars()); } } + Printf("First free %u\n", FirstFreeEntry); } //============================================================================ diff --git a/src/p_acs.h b/src/p_acs.h index 1a0fb3f60..ec41ab886 100644 --- a/src/p_acs.h +++ b/src/p_acs.h @@ -100,6 +100,7 @@ public: private: int FindString(const char *str, size_t len, unsigned int h, unsigned int bucketnum); int InsertString(FString &str, unsigned int h, unsigned int bucketnum, const SDWORD *stack, int stackdepth); + void FindFirstFreeEntry(unsigned int base); enum { NUM_BUCKETS = 251 }; enum { FREE_ENTRY = 0xFFFFFFFE }; // Stored in PoolEntry's Next field