Changeset - r8040:e05f3ded186d
[Not reviewed]
master
0 10 0
glx - 16 years ago 2007-12-08 15:47:23
glx@openttd.org
(svn r11600) -Cleanup: remove extra out-of-memory checks, since it's now done in *allocT functions.
10 files changed with 4 insertions and 26 deletions:
0 comments (0 inline, 0 general)
src/group_gui.cpp
Show inline comments
 
@@ -40,25 +40,19 @@ static void BuildGroupList(grouplist_d* 
 
	const Group *g;
 
	uint n = 0;
 

	
 
	if (!(gl->l.flags & VL_REBUILD)) return;
 

	
 
	list = MallocT<const Group*>(GetGroupArraySize());
 
	if (GetGroupArraySize() != 0 && list == NULL) {
 
		error("Could not allocate memory for the group-sorting-list");
 
	}
 

	
 
	FOR_ALL_GROUPS(g) {
 
		if (g->owner == owner && g->vehicle_type == vehicle_type) list[n++] = g;
 
	}
 

	
 
	free((void*)gl->sort_list);
 
	gl->sort_list = MallocT<const Group *>(n);
 
	if (n != 0 && gl->sort_list == NULL) {
 
		error("Could not allocate memory for the group-sorting-list");
 
	}
 
	gl->l.list_length = n;
 

	
 
	for (uint i = 0; i < n; ++i) gl->sort_list[i] = list[i];
 
	free((void*)list);
 

	
 
	gl->l.flags &= ~VL_REBUILD;
src/industry_gui.cpp
Show inline comments
 
@@ -749,13 +749,12 @@ static void MakeSortedIndustryList()
 
{
 
	const Industry* i;
 
	int n = 0;
 

	
 
	/* Create array for sorting */
 
	_industry_sort = ReallocT(_industry_sort, GetMaxIndustryIndex() + 1);
 
	if (_industry_sort == NULL) error("Could not allocate memory for the industry-sorting-list");
 

	
 
	/* Don't attempt a sort if there are no industries */
 
	if (GetNumIndustries() != 0) {
 
		FOR_ALL_INDUSTRIES(i) _industry_sort[n++] = i;
 
		qsort((void*)_industry_sort, n, sizeof(_industry_sort[0]), GeneralIndustrySorter);
 
	}
src/map.cpp
Show inline comments
 
@@ -49,20 +49,19 @@ void AllocateMap(uint size_x, uint size_
 
	_map_size = size_x * size_y;
 
	_map_tile_mask = _map_size - 1;
 

	
 
	free(_m);
 
	free(_me);
 

	
 
	_m = CallocT<Tile>(_map_size);
 
	_me = CallocT<TileExtended>(_map_size);
 

	
 
	/* XXX @todo handle memory shortage more gracefully
 
	 * CallocT does the out-of-memory check
 
	 * Maybe some attemps could be made to try with smaller maps down to 64x64
 
	 * Maybe check for available memory before doing the calls, after all, we know how big
 
	 * the map is */
 
	if ((_m == NULL) || (_me == NULL)) error("Failed to allocate memory for the map");
 
	_m = CallocT<Tile>(_map_size);
 
	_me = CallocT<TileExtended>(_map_size);
 
}
 

	
 

	
 
#ifdef _DEBUG
 
TileIndex TileAdd(TileIndex tile, TileIndexDiff add,
 
	const char *exp, const char *file, int line)
src/network/network_gui.cpp
Show inline comments
 
@@ -164,13 +164,12 @@ static void BuildNetworkGameList(network
 
	for (ngl_temp = _network_game_list; ngl_temp != NULL; ngl_temp = ngl_temp->next) n++;
 
	if (n == 0) return;
 

	
 
	/* Create temporary array of games to use for listing */
 
	free(nqld->sort_list);
 
	nqld->sort_list = MallocT<NetworkGameList*>(n);
 
	if (nqld->sort_list == NULL) error("Could not allocate memory for the network-game-sorting-list");
 
	nqld->l.list_length = n;
 

	
 
	for (n = 0, ngl_temp = _network_game_list; ngl_temp != NULL; ngl_temp = ngl_temp->next) {
 
		nqld->sort_list[n++] = ngl_temp;
 
	}
 

	
src/newgrf.cpp
Show inline comments
 
@@ -5418,13 +5418,12 @@ static void DecodeSpecialSprite(uint num
 
	byte* buf;
 

	
 
	if (_preload_sprite == NULL) {
 
		/* No preloaded sprite to work with; allocate and read the
 
		 * pseudo sprite content. */
 
		buf = MallocT<byte>(num);
 
		if (buf == NULL) error("DecodeSpecialSprite: Could not allocate memory");
 
		FioReadBlock(buf, num);
 
	} else {
 
		/* Use the preloaded sprite data. */
 
		buf = _preload_sprite;
 
		_preload_sprite = NULL;
 
		grfmsg(7, "DecodeSpecialSprite: Using preloaded pseudo sprite data");
src/oldpool.cpp
Show inline comments
 
@@ -52,18 +52,15 @@ bool OldMemoryPoolBase::AddBlockToPool()
 
	this->total_items = (this->current_blocks + 1) * (1 << this->block_size_bits);
 

	
 
	DEBUG(misc, 4, "[Pool] (%s) increasing size of pool to %d items (%d bytes)", this->name, this->total_items, this->total_items * this->item_size);
 

	
 
	/* Increase the poolsize */
 
	this->blocks = ReallocT(this->blocks, this->current_blocks + 1);
 
	if (this->blocks == NULL) error("Pool: (%s) could not allocate memory for blocks", this->name);
 

	
 
	/* Allocate memory to the new block item */
 
	this->blocks[this->current_blocks] = MallocT<byte>(this->item_size * (1 << this->block_size_bits));
 
	if (this->blocks[this->current_blocks] == NULL)
 
		error("Pool: (%s) could not allocate memory for blocks", this->name);
 

	
 
	/* Clean the content of the new block */
 
	memset(this->blocks[this->current_blocks], 0, this->item_size * (1 << this->block_size_bits));
 

	
 
	/* Call a custom function if defined (e.g. to fill indexes) */
 
	if (this->new_block_proc != NULL) this->new_block_proc(this->current_blocks * (1 << this->block_size_bits));
src/signs_gui.cpp
Show inline comments
 
@@ -44,13 +44,12 @@ static void GlobalSortSignList()
 
{
 
	const Sign *si;
 
	uint n = 0;
 

	
 
	/* Create array for sorting */
 
	_sign_sort = ReallocT(_sign_sort, GetMaxSignIndex() + 1);
 
	if (_sign_sort == NULL) error("Could not allocate memory for the sign-sorting-list");
 

	
 
	FOR_ALL_SIGNS(si) _sign_sort[n++] = si;
 
	_num_sign_sort = n;
 

	
 
	qsort((void*)_sign_sort, n, sizeof(_sign_sort[0]), SignNameSorter);
 

	
src/spritecache.cpp
Show inline comments
 
@@ -50,16 +50,12 @@ static SpriteCache *AllocateSpriteCache(
 
		uint items = Align(index + 1, 1024);
 

	
 
		DEBUG(sprite, 4, "Increasing sprite cache to %d items (%d bytes)", items, items * sizeof(*_spritecache));
 

	
 
		_spritecache = ReallocT(_spritecache, items);
 

	
 
		if (_spritecache == NULL) {
 
			error("Unable to allocate sprite cache of %d items (%d bytes)", items, items * sizeof(*_spritecache));
 
		}
 

	
 
		/* Reset the new items and update the count */
 
		memset(_spritecache + _spritecache_items, 0, (items - _spritecache_items) * sizeof(*_spritecache));
 
		_spritecache_items = items;
 
	}
 

	
 
	return GetSpriteCache(index);
 
@@ -408,14 +404,13 @@ static void DeleteEntryFromSpriteCache()
 
			best = i;
 
		}
 
	}
 

	
 
	/* Display an error message and die, in case we found no sprite at all.
 
	 * This shouldn't really happen, unless all sprites are locked. */
 
	if (best == (uint)-1)
 
		error("Out of sprite memory");
 
	if (best == (uint)-1) error("Out of sprite memory");
 

	
 
	/* Mark the block as free (the block must be in use) */
 
	s = (MemBlock*)GetSpriteCache(best)->ptr - 1;
 
	assert(!(s->size & S_FREE_MASK));
 
	s->size |= S_FREE_MASK;
 
	GetSpriteCache(best)->ptr = NULL;
src/station_gui.cpp
Show inline comments
 
@@ -225,13 +225,12 @@ static void BuildStationsList(plstations
 
	const Station *st;
 

	
 
	if (!(sl->flags & SL_REBUILD)) return;
 

	
 
	/* Create array for sorting */
 
	const Station** station_sort = MallocT<const Station*>(GetMaxStationIndex() + 1);
 
	if (station_sort == NULL) error("Could not allocate memory for the station-sorting-list");
 

	
 
	DEBUG(misc, 3, "Building station list for player %d", owner);
 

	
 
	FOR_ALL_STATIONS(st) {
 
		if (st->owner == owner) {
 
			if (facilities & st->facilities) { //only stations with selected facilities
 
@@ -252,13 +251,12 @@ static void BuildStationsList(plstations
 
			}
 
		}
 
	}
 

	
 
	free((void*)sl->sort_list);
 
	sl->sort_list = MallocT<const Station*>(n);
 
	if (n != 0 && sl->sort_list == NULL) error("Could not allocate memory for the station-sorting-list");
 
	sl->list_length = n;
 

	
 
	for (uint i = 0; i < n; ++i) sl->sort_list[i] = station_sort[i];
 

	
 
	sl->flags &= ~SL_REBUILD;
 
	sl->flags |= SL_RESORT;
src/town_gui.cpp
Show inline comments
 
@@ -446,13 +446,12 @@ static void MakeSortedTownList()
 
{
 
	const Town* t;
 
	uint n = 0;
 

	
 
	/* Create array for sorting */
 
	_town_sort = ReallocT(_town_sort, GetMaxTownIndex() + 1);
 
	if (_town_sort == NULL) error("Could not allocate memory for the town-sorting-list");
 

	
 
	FOR_ALL_TOWNS(t) _town_sort[n++] = t;
 

	
 
	_num_town_sort = n;
 

	
 
	_last_town = NULL; // used for "cache"
0 comments (0 inline, 0 general)