new problems with array of pointers
Greets again... with the rate I''m going, I''ll get 2 new ranks before my game is done! Anyway, Im having trouble when trying to cache bitmaps when loading a map file. I have an array of type TSetEntry* TileCache[256]. When I want to add a tile to TileCache, I TileCache = new TSetEntry. When this is done, the contents of TileCache are set to -8456678 like any normal uninitialized variable. When I try to read the TSetEntry from the file to TileCache, the variables in TileCache turn into "CXX0030: Error: expression cannot be evaluated". Here is the code… if you need any more info, please let me know.. Ive been stuck here for a bit so Im anxious to move forward.
//World is a 1-D array of type GridStruct (map points)… supposedly new doesnt work with 2+-D arrays =(
while(i < MHeader_t.iNumGrids) //MHeader_t.iNumGrids =
MapSizeX + MapSizeY
{
while(j < World.iNumTiles) //up to 3 tiles per grid
{
//if this tile# not already loaded
if(bTileLoaded[World.iTileIndex[j]] == false)
{
//*****FIX THIS*****
//allocate TSetEntry pointer
TileCache[World.iTileIndex[j]] = new TSetEntry;
//seek to entry point in the file
hInTSet.seekg(
THeader_t.lByteOffsets[World.iTileIndex[j]],
ios::beg);
//read in bitmap
hInTSet.read(reinterpret_cast <char*>
(&TileCache[World.iTileIndex[j]]),
THeader_t.lEntrySizes[World.iTileIndex[j]]);
//tile# loaded successfully (eventually!!)
bTileLoaded[World.iTileIndex[j]] = true;
}
j++;
}
j = 0; //reset TileIndex counter
i++;
}
Thanks again!!
</i>
There is no spoon.
//read in bitmap hInTSet.read(reinterpret_cast (&TileCache[World<i>.iTileIndex[j]]), THeader_t.lEntrySizes[World[i].iTileIndex[j]]);
The problem is this: &TileCache[...] . Since memory is allocated where TileCache[...] points, not where it resides, you don''t want the address-of operator for this expression. Remove the & and all should be fine.
What''s happening is that you''re reading directly into where &TileCache[...] is stored, so the memory you just allocated with it is lost, and it now points to some bogus memory location, and the debugger tries to read from there, and can''t. I''m assuming that TSetEntry is some sort of structure, so the debugger probably can''t make sense of what it''s reading at the new address.
Hope this helps.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement