Changeset - r20910:0cfca604a1aa
[Not reviewed]
master
0 1 0
rubidium - 11 years ago 2013-11-08 22:28:57
rubidium@openttd.org
(svn r25956) -Fix [FS#5772]: temporary persistent storage modifications, e.g. command tests or those from GUI, were not properly reset, creating the possibility of desyncs
1 file changed with 2 insertions and 1 deletions:
0 comments (0 inline, 0 general)
src/newgrf_storage.h
Show inline comments
 
@@ -75,25 +75,25 @@ struct PersistentStorageArray : BaseStor
 
	 * @param value the value to write
 
	 */
 
	void StoreValue(uint pos, int32 value)
 
	{
 
		/* Out of the scope of the array */
 
		if (pos >= SIZE) return;
 

	
 
		/* The value hasn't changed, so we pretend nothing happened.
 
		 * Saves a few cycles and such and it's pretty easy to check. */
 
		if (this->storage[pos] == value) return;
 

	
 
		/* We do not have made a backup; lets do so */
 
		if (this->prev_storage != NULL) {
 
		if (this->prev_storage == NULL) {
 
			this->prev_storage = MallocT<TYPE>(SIZE);
 
			memcpy(this->prev_storage, this->storage, sizeof(this->storage));
 

	
 
			/* We only need to register ourselves when we made the backup
 
			 * as that is the only time something will have changed */
 
			AddChangedStorage(this);
 
		}
 

	
 
		this->storage[pos] = value;
 
	}
 

	
 
	/**
 
@@ -112,24 +112,25 @@ struct PersistentStorageArray : BaseStor
 
	/**
 
	 * Clear the changes, or assign them permanently to the storage.
 
	 * @param keep_changes Whether to assign or ditch the changes.
 
	 */
 
	void ClearChanges(bool keep_changes)
 
	{
 
		assert(this->prev_storage != NULL);
 

	
 
		if (!keep_changes) {
 
			memcpy(this->storage, this->prev_storage, sizeof(this->storage));
 
		}
 
		free(this->prev_storage);
 
		this->prev_storage = NULL;
 
	}
 
};
 

	
 

	
 
/**
 
 * Class for temporary storage of data.
 
 * On #ClearChanges that data is always zero-ed.
 
 * @tparam TYPE the type of variable to store.
 
 * @tparam SIZE the size of the array.
 
 */
 
template <typename TYPE, uint SIZE>
 
struct TemporaryStorageArray : BaseStorageArray {
0 comments (0 inline, 0 general)