Archived

This topic is now archived and is closed to further replies.

Orpheum

new problems with array of pointers

Recommended Posts

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[i] = new TSetEntry. When this is done, the contents of TileCache[i] are set to -8456678 like any normal uninitialized variable. When I try to read the TSetEntry from the file to TileCache[i], the variables in TileCache[i] 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[i].iNumTiles) //up to 3 tiles per grid { //if this tile# not already loaded if(bTileLoaded[World[i].iTileIndex[j]] == false) { //*****FIX THIS***** //allocate TSetEntry pointer TileCache[World[i].iTileIndex[j]] = new TSetEntry; //seek to entry point in the file hInTSet.seekg( THeader_t.lByteOffsets[World[i].iTileIndex[j]], ios::beg); //read in bitmap hInTSet.read(reinterpret_cast (&TileCache[World[i].iTileIndex[j]]), THeader_t.lEntrySizes[World[i].iTileIndex[j]]); //tile# loaded successfully (eventually!!) bTileLoaded[World[i].iTileIndex[j]] = true; } j++; } j = 0; //reset TileIndex counter i++; } Thanks again!!

Share this post


Link to post
Share on other sites
    
//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.

Share this post


Link to post
Share on other sites
Well you fixed one error, but caused another... no I get an Access Violation when it hits the read statement without the & present. Any more ideas?

Share this post


Link to post
Share on other sites