hi im having a problem when i call a function for an object in a vector. when i call the objects function when its not in the vector, it works fine, but if i call it in the vector i get an sdl error telling me the surface needs to be locked, even though i dont ever need pixel access, and it doesnt cause the error when called normally. heres what im doing :
Code:
testTile.draw(20,20);
testTile.draw(40,20);
testTile.draw(40,40);
tiles[0][0].draw(80, 70);
BlitSurface errorSurfaces must not be locked during blit is the error i get.
the tiles are all initializing fine, coz other methods work, so im not sure whats causing the problem.
any help will be great.
thanks rob
below is the code in full context
Code:
bool Map::init(char *mapName){
ifstream mapFile(mapName);
if(!mapFile.is_open()){ // could not open file
cout << "Unable to open Map " << mapName << "\n";
mapFile.close();
return false;
}
else{ // continue to read map
cout << mapName << " loaded\n";
mapFile >> mapWidth >> mapHeight >> tileWidth >> tileHeight >> xOffset >> yOffset;
vector< vector<Tile> > loadedTiles(mapHeight, vector<Tile>(mapWidth));
testTile.init("stone.bmp", 1, 1);
for(int j = 0; j < 1; j++){ // also here if i make this loop any larger i get Fatal signal: Segmentation Fault (SDL Parachute Deployed)
for(int i = 0; i < mapWidth; i++){
char filename[256];
int passable, transparent;
mapFile >> filename >> passable >> transparent;
loadedTiles[i][j].init(filename, passable, transparent);
loadedTiles[i][j].toString();
}
}
mapFile.close();
tiles = loadedTiles;
return true;
}
} // end init
bool Map::draw(){
testTile.draw(20,20);
testTile.draw(40,20);
testTile.draw(40,40); // ALL DRAW FINE
tiles[0][0].toString(); // WORKS
tiles[0][0].draw(80, 70); // CAUSES SDL ERROR
/*
for(int j = 0; j < mapHeight; j++){
for(int i = 0; i < mapWidth; i++){
tiles[i][j].toString();
}
}*/
return true;
} // end draw