I'm trying to create a framework for a Room in a text game exercise. The way the game works is that Rooms are classes, which contain pointers to arrays of pointers to Tiles, and each tile has a pointer to a Container that represents items that are on the Tile.
The implementation of this is pretty simple, and it compiles fine. I'm having some problems, however, when I try to 'place' a Thing object 'onto' a Tile. This is done through passing a pointer to a Thing object through multiple passthrough functions. The pointer is passed to the Tile's placeOnTile(Thing * i) function, which passes it to the Tile's Container's addItem(Thing* th) function, which runs a simple check to make sure it fits in the Container (with a compare to a maxSize int), then returns true if it does fit.
According to a debug watch, the pointer (named placer) is not changing through the passes (this is good). However, when it reaches the final passthrough function (that of the Container's addItem(Thing* th)), it will segfault and not continue running the program.
The relevant code samples I could think of are listed below. If there is more I should include please let me know.
in main:
cout << "Bedroom Demo" << endl << endl;
cout << "Creating bedroom obj...";
Bedroom b1; //this calls the constructor for Bedroom
cout << "done." << endl << endl;
in Bedroom.h:
Bedroom() //constructor
{
makeNineSquare(1); //this creates an arry of 9 Tiles, arranged in a 3x3 grid
Thing* placer; //this will point to objects that you'll create
placer = new Bed("Your bed","This is your bed.",false,false,true,1); //constructor
ti[2]->placeOnTile(placer); //!!!!This is where the error occurs!!!!
placer = new Decor("North-facing Window","The window to the north looks out into barren space",false,false,true);
ti[1]->placeOnTile(placer);
placer = new Desk("Your desk","Your desk is wooden and antique.",0,0,1,5);
ti[3]->placeOnTile(placer);
delete placer; //for memory leaks
}
in Tile.h:
bool placeOnTile(Thing * i){return onTile->addItem(i);}
in Container.h (onTile is a Container object encapsulated in Tile):
bool addItem(Thing* th);
in Container.cpp:
bool Container::addItem(Thing* th)
{
if (numItems < maxSize)
{
contents[++numItems] = th;
return true;
}
else return false;
}
As I mentioned above, a debug watch shows that every step of the 'passing' works fine except the final passthrough (that of Container). What am I doing wrong?
Note: ti is declared inside Bedroom. It's an array of 9 tiles, 0 through 8, that make up the 'room'. The function makeNineSquare is just a function that implements a two-dimensional linked list on the array, creating NESW pointers to the adjacent Tiles. The reason I've created it like this is to facilitate placement on certain tiles with the array (as shown in the code provided), and to facilitate easy traversal of the grid by an object (such as a Player) with the pointers.
This also allows for global, generic move commands (moveN is just curr = curr->getN instead of a calculation to determine if, say, 7 is adjacent to 2).
According to your code I have no idea what numitems is but check if numitems++ is causing an array out of index.
Related
I am creating a grid game in which each box in the grid is a district and represents some people along with their specific ID.
Now I have a function here which locates where the exact person is in the grid in particular box.
Here is my function.
bool where(int id, int &row, int &col)const
{
person* per;
for(int i=0;i<alive.size();i++)
{
std::cout<<alive[i]<<std::endl; //This is just for testing the person number
if (alive[i]->person_id == id)
{
p = alive[i];
break;
}
}
}
My Question: The test code std::cout<<alive[i]<<std::endl; is always printing the address of the number. I tried many things but I couldn't figure it out.
Edit: Here alive is a vector
Can anyone please help me.
Consider this line in your code: if (alive[i]->person_id == id). The fact that it uses -> rather than . indicates that alive isn't a vector of some struct/class, but is rather a vector of pointers (or potentially some other object that acts like a pointer) to some struct/class. As such, to print the actual object, do std::cout<<*alive[i]<<std::endl; (note the added *).
So I have a vector:
vector<Enemy*> enemies;
This vector hold enemies, which are created dynamically throughout the game.
if(rand() % 1000 > 998)
{
Enemy * enemy = new Enemy(num_of_enemies);
enemies.push_back(enemy);
}
The problem with this being is that the vector is ever growing even if the enemy has been deleted, which is slowing down my game.
Essentially I want to move the contents of the vector to a new one, but only the elements that actually hold an enemy.
I read that there was something called std::move but I'm not really sure how to implement it properly, or if it will successfully move the elements that contain enemies, and not just the whole vector.
Any help with code implementation of structuring would be greatly appreciated.
Here’s a complete workflow of how to handle spawning and despawning enemies. Note that there are no pointers at all involved.
Spawning an enemy:
if (if random_float_between_0_and_1() < 0.002)
enemies.push_back(Enemy{arguments});
Despawning enemies; according to your comment below, should look something like this:
auto last_iter = std::remove_if(enemies.begin(), enemies.end(), is_dead);
enemies.erase(last_iter, enemies.end());
Here, is_dead is a function that takes an Enemy const& and determines whether it collided with a player or the screen bounds:
bool is_dead(Enemy const& enemy) {
return outside_screen_area(enemy) or near_player(enemy);
}
The functions outside_screen_area and near_player should be straightforward for you to implement.
To understand how the code above works, consult the documentations of std::remove and std::vector::erase.
Another thing: implement the function random_float_between_0_and_1 in terms of the standard library random library that ships with C++11. Don’t use std::rand or modulo operations on integer random numbers, they work badly (i.e. they’re not truly uniformly distributed and will give skewed results).
The problem with this being is that the vector is ever growing even if the enemy has been deleted ...
Essentially I want to move the contents of the vector to a new one ...
It seems to me that a simpler approach would be to remove the pointers to deleted objects from the original vector instead of making a copy.
There is no difference between a pointer to a deleted object that no longer exists and a pointer to an existing object. Therefore you must keep track of the elements that must be removed from the vector. The simplest solution is to remove the element immediately after it has been deleted. This becomes much easier with smart pointers since removing the pointer also deletes the object automatically.
std::move won't help you with this problem.
You may want to consider not using manual dynamic allocation at all. You can instead store Enemy objects in the vector.
When the enemy is to be deleted I call the class destructor, and than [sic] I delete
delete expression calls the destructor. Calling it yourself also will have undefined behaviour.
First of all, I suggest you shouldn't use a data structure like std::vector if you want to remove a single element in a random position. The complexity of this operation is linear on the number of elements after the deleted element.
As I understand, you have a number of enemies moving around a 2D screen side by side with one (or many) player(s). If an enemy is hit by a player or goes out of the screen, it will be deleted. You just loop over the list of enemies to see these conditions fulfilled.
In this case, I recommend you to use std::map to manage your created enemy objects.
Suppose that your Enemy class has a function to check deletion conditions, e.g:
bool Enemy::willbeDeleted() /* if true then will be deleted */
then here is a class using std::map to manage your enemy objects:
EnemyManager.hpp
#include <map>
class EnemyManager {
public:
/*
* Get the Enemy Manager
*/
static EnemyManager& Instance();
/*!
* Delete the instance of EnemyManager
*/
static void deleteInstance();
public:
/* Create an enemy object */
void createEnemy();
/* Check all enemy objects and delete any fulfulling condition */
void checkEnemy();
virtual ~EnemyManager();
private:
/* Make sure we can not call EnemyManager constructor directly */
EnemyManager();
EnemyManager(const EnemyManager& objManager);
/* Instance of EnemyManager */
static EnemyManager* enemyManager;
private:
/* List of current enemy objects */
std::map<int, A*> enemyList_;
/* Identity of already-create object, it increases on creating a new object */
int enemyIndex_;
};
EnemyManager.cpp
#include "EnemyManager.hpp"
#include <vector>
EnemyManager* EnemyManager::enemyManager = 0;
EnemyManager& EnemyManager::Instance()
{
if (0 == enemyManager)
{
enemyManager = new EnemyManager();
}
return *enemyManager;
}
void EnemyManager::deleteInstance()
{
if (0 != enemyManager) delete enemyManager;
}
EnemyManager::EnemyManager() : enemyList_(), enemyIndex_(0)
{}
EnemyManager::~EnemyManager() {
/* Nothing todo */
}
void EnemyManager::createEnemy()
{
enemyList_[enemyIndex_] = new Enemy();
++enemyIndex_;
}
void EnemyManager::checkEnemy()
{
std::map<int, A*>::const_iterator itb = enemyList_.begin(),
ite = enemyList_.end(), it;
// Vector containing id of enemy object to delete
std::vector<int> enemyToDelete;
for (it = itb; it != ite; ++it)
if ((it->second)->willbeDeleted())
enemyToDelete.push_back(it->first);
// Delete enemies and remove them from map
for (std::size_t idx = 0; idx < enemyToDelete.size(); ++idx)
{
delete enemyList_[enemyToDelete[idx]];
enemyList_.erase(enemyToDelete[idx]);
}
}
you can use this class as follow :
in main.cpp
EnemyManager& enemyManager = EnemyManager::Instance();
if(rand() % 1000 > 998)
{
/* Create new enemy */
enemyManager.createEnemy();
}
/* Check all enemies */
enemyManager.checkEnemy();
There are two important functions: createEnemy controls the way to create a new Enemy object, checkEnemy verifies objects and deletes them if needed and the size of enemyList_ won't increase forever :)
I believe with this approach, deleting enemies won't slow down your program anymore.
One of a drawback of this approach is that the number of created objects can be limited by 2^(8*sizeof(enemyIndex_))
everyone!
I just finished writing a 2-D maze (Class is an ADT titled "Maze"--how original) that uses dynamic memory allocation. I'm passing the Maze to a method of another class I've entitled "MazeSolver," which uses recursion and backtracking to solve the maze. Good news is my code compiles wonderfully when I pass the object by reference. News that I don't know if is good or bad is that I get an assertion error if I try to pass the Maze to MazeSolver by value.
Given that the error occurs only when I pass by value, I can only assume it has something to do with my copy constructor. Before going any further, here's some info on the code:
Maze is composed of squares. Each square is represented by a struct called SquareData.
struct SquareData
{
//data fields for the struct (NO POINTERS)
}
I've decided to represent the entire maze with a vector of SquareData pointers (this vector is in private section of the class "Maze").
vector<SquareData*> squares;
Implementation of my destructor looks like this (that last call referencing a Player class is just eliminating a dangling pointer I have declared as a static variable for that class, which I have pointing at the maze. I don't think it's important considering the question, but I am new to C++ after all and one of you may think it might be, so I've included it for "hmmms"):
// clears maze of its contents
void Maze::clear() {
int totalSquares = squares.size();
for (int loopVar = 0; loopVar < totalSquares; loopVar++)
{
delete squares[loopVar]; // deallocate memory by deleting the square structure
squares[loopVar] = nullptr; // eliminate dangling pointer
} // vector takes care of itself
} // end clear
Maze::~Maze(){
//clear the maze of contents (vector is full of pointers whose memory is on the heap)
clear();
//vector safe to deallocate itself now
Player::setMaze(nullptr); // remove the pointer from player
}
I've declared the copy constructor in header as follows:
/** Copy Constructor */
Maze(const Maze& myMaze);
with attempted implementation:
/** copy constructor */
Maze::Maze(const Maze& myMaze){
/** Initialize Constants */
mazeLength = myMaze.mazeLength;
mazeWidth = myMaze.mazeWidth;
exitRow = myMaze.exitRow;
exitCol = myMaze.exitCol;
entRow = myMaze.entRow;
entCol = myMaze.entCol;
/** copy the vector of pointers*/
for (int loopVar = 0; loopVar < myMaze.squares.size(); loopVar++)
{
squares.push_back(myMaze.squares[loopVar]);
}
} // end copy constructor
Here's how I attempted to understand what the problem was doing:
I wrote this vector display function in for my Maze class.
void Maze::vectorDisplay() const {
for (int loopVar = 0; loopVar < squares.size(); loopVar++)
{
cout << "Vector Index: " << loopVar << endl;
cout << "Pointer: " << squares[loopVar] << endl;
cout << "Row: " << squares[loopVar]->Row << endl;
cout << "Col: " << squares[loopVar]->Col << endl;
cout << "State: " << squares[loopVar]->State << endl;
}
} //end vectorDisplay
And found that the vector displays correctly when doing the following in the driver:
Maze myMazeObject(// parameters);
myMazeObject.vectorDisplay();
and will produce output with no complaints.
But now if I try to use code like this when passing by value:
Maze myMazeObject(// parameters);
MazeSolver myMazeSolver;
myMazeSolver.someMazeSolverMethod(myMazeObject);
where someMazeSolverMethod has the line myMazeObject.vectorDisplay();I get an assertion error just as the final element in the vector is being printed.
I want to say this is my fault and my copy constructor is a p.o.s. If any insight, please let me know how to fix it and what I can do in the future!
Thanks for taking the time to read and even more so to answer should you choose to!
-J
This is your problem.
squares.push_back(myMaze.squares[loopVar]);
Basically each Maze has a vector full of the same pointers. When one copy of the maze goes out of scope it will delete all the pointers. Thus the other Maze now has a set of invalid pointers.
Couple of solutions.
Don't use pointers.
Unless you SquareData is polymorphic there seems no reason to keep pointers.
std::vector<SquareData> squares;
If you want each copy of the maze to refer to the same squares.
Then use a shared pointer. This will keep a count of the number of references to each SquareData and thus only delete them when they truly go out of scope.
std::vector<std::shared_ptr<SquareData>> squares;
Least attractive (and probably not needed).
Change the code to actually copy the pointer content into a new object.
squares.push_back(new SquareData(myMaze.squares[loopVar]));
Use of
squares.push_back(myMaze.squares[loopVar]);
in the copy constructor will lead to problems downstream.That will be vaild had the contents of squares been objects not pointers.
There are now two objects holding on to the pointers. Both willl try to call delete on the same pointer, which easily leads to undefined behavior.
You can fix the problem by:
Using a vector objects instead of a vector of pointers, or
Creating new objects from the heap and adding them to the new object.
squares.push_back(new SquareData(*myMaze.squares[loopVar]));
I store the data in a double std::vector structure, which I need to be able to fill and clear repeatedly: this is causing some allocation issues I don't understand.
I am using a structure vector<Coefficients *> XSims, where Coefficients takes the form
class Coefficients{
int N;
public:
vector<gsl_vector *> Coefs;
//Iterator to traverse the vector structure.
vector<gsl_vector*>::iterator it;
void it_start(){
it = Coefs.begin();
}
void it_end(){
it = Coefs.end();
}
void it_next(){
++it;
}
void it_prev(){
--it;
}
bool not_end(){
return it < Coefs.end();
}
//Return number of vectors contained.
size_t length(){return Coefs.size();}
//Append pointer to outside data into the Coefs structure.
void append( gsl_vector * X ){
Coefs.push_back(X);
}
Coefficients(int N1) : N(N1) {
Coefs.reserve(N);
}
//Clean up procedure
void Clear(){
//Forward iterator.
it_start();
while(not_end()){
gsl_vector_free((*it));
it_next();
}
Coefs.clear();
}
~Coefficients(){
//Forward iterator.
Clear();
Coefficients::Coefs.clear();
}
};
I use the following iterator to get around XSim:
vector<Coefficients *>::iterator Xit;
inline void Xstart(){Xit = XSims.begin();}
inline void Xend(){Xit = XSims.end();}
inline void X_next(){++Xit;}
inline void X_previous(){--Xit;}
inline bool X_not_end(){return {Xit < XSims.end()};}
The two functions I'm struggling to use in combination are as follows:
inline void Simulate(){
XSims.reserve(N+1);
Xstart();
for(int i=0;i<N; i++){
//Build a container to insert into XSims
Coefficients * XsimsIteration = new Coefficients(1000);
// time points to previous vector of simulations.
(*Xit)->it_start();
for(int m=0;m<1000;m++){
//Allocate free space for the components of the DW and Xsims.
gsl_vector * X = gsl_vector_alloc(X0.X0->size);
XsimsIteration->append(X);
gsl_vector_memcpy(X,(*Xit));
//Next simulation
(*Xit)->it_next();
}
cout << "Number of sims being inserted into X = " << XsimsIteration->length() << endl;
//Insert XsimsIteration into the XSims container
XSims.push_back(XsimsIteration);
//next time point
X_next();
cout << "Number of simulations stored in X = " << (*Xit)->length() << endl;
}
}
inline void XW_clear(){
Xstart();
//Don't want to clear the initial values, so step forward!
X_next();
while(X_not_end()){
(*Xit)->Clear();
X_next();
}
XSims.clear();
}
I want to run the two functions in loop: After initializing the XSims with an initial Coeffiecient* (which never gets cleared), I run
Simulate();
XW_clear();
Simulate();
The first two functions work fine, but the second Simulate() crashes in run-time. Basically, it seems not to want to push_back the XsimsIteration on the second outer-loop: I get the strange output:
Number of sims being inserted into X = 1000
Number of simulations stored in X = 0
The second Number of simulations stored in X should in fact be the same as the first, i.e. 1000.
Your test for the end is not correct
inline bool X_not_end(){return {Xit < XSims.end()};}
This kind of test will work, if you have plain C/C++ arrays, but it need not work with containers. The test should be Xit != XSims.end(), not <, so it should read
inline bool X_not_end(){return Xit != XSims.end();}
Same goes for Coefficients::not_end().
Taking a look at this:
inline void Simulate(){
XSims.reserve(N+1);
Xstart();
for(int i=0;i<N; i++){
//Build a container to insert into XSims
Coefficients * XsimsIteration = new Coefficients(1000);
// time points to previous vector of simulations.
(*Xit)->it_start();
I see that you have reserved some memory for XSims. Then you call XStart() which executes XSims.begin(). You are calling a member function begin on a vector with zero elements. That seems like a red flag to me right there. Since you posted your code on a public domain, I can't help but critique it. It seems like you are obfuscating some very simple operations such as incrementing a decrementing an interator. The calls to begin, end, and moving forward and backward are already very simple. All that you have done is to make your program difficult to read.
Then you will use that iterator which is not valid to call a function on a nonexisting Coeffecients object. Only after the for loop which comes later do you actually put something into the vector.
The following lines of code are being executed before you put any elements into the XSims vector.
(*Xit)->it_start();
(*Xit)->it_next(); // why is this in the for loop? You are iterating over an empty vector
For future reference, I highly recommend that you post a compilable example. You will typically learn a lot during the process, and often one will find their own problem while doing so and debugging. In this case one has to assume many things about what you might or might not be doing in the actual executable program.
It worked if I cleared the XSims from the back rather than from the front, I guess it was throwing out everything including the initial value that I wanted to keep.
I'm compiling using Code::Blocks on Windows 7 using the MinGW compiler (which I can only assume is the latest version; both Code::Blocks and MinGW were installed this past week). My issue crops up under a particular circumstance, and my attempts to write a simpler script that demonstrates the problem have failed (which implies that there is something wrong with my structure). Also, my apologies for how long this post is.
Currently, I'm rolling with one class, FXSDL, which will act as an SDL wrapper:
class FXSDL
{
public:
FXSDL();
virtual ~FXSDL();
int Initialize();
int Render();
FXID CreateCharacter(FXID hRefID, string fpImage, int wpxTile, int hpxTile, map<int, vector<int> > htAnims);
int SetAnim(FXID hRefID, FXID hAnimID);
FXID hPlayer;
protected:
private:
list<FXSurface> m_lstFXObjects;
list<FXSurface>::iterator m_liFirst;
SDL_Surface* m_lpsfSDLScreen;
Uint32 m_tmOld;
Uint32 m_tmFrame;
};
The value type of my list is:
struct FXSurface
{
FXID hRefID;
int wpxTile;
int hpxTile;
int wpxTotal;
int hpxTotal;
int cntTiles;
map<int, vector<int> > htAnims; // All animations
map<int, vector<int> >::iterator vCurr; // Currently active animation
vector<int>::iterator fiCurr; // Currently active frame
SDL_Surface* lpsfSDL;
SDL_Rect* lprcTiles; // Predefined frame positions
string* fpImage;
};
I've implemented very simple initialize and render function. The CreateCharacter function takes a few parameters, the most important of which is htAnims, a map of integer vectors (idea being: I define numeric ids with easy-to-remember representations, such as FXA_IDLE or FXA_WALK, as the key, and the series of number values representing frames for the animation as a vector). This could be fairly easily implemented as a multidimensional integer array, but animations are variable in length and I want to be able to add new anims (or redefine existing ones) without having to recast an array.
The CreateCharacter function is simple. It creates a new FXSurface, populates it with the required data, and pushes the new FXSurface onto the list:
FXID FXSDL::CreateCharacter(FXID hRefID, string fpImage, int wpxTile, int hpxTile, map<int, vector<int> > htAnims)
{
//list<FXSurface>::iterator lpsfTemp;
FXSurface lpsfTemp;
list<FXSurface>::iterator lpsfPos;
SDL_Rect* lprcCurr = NULL;
int cntTileW = 0;
int cntTileH = 0;
int cntCurr = 0;
// Start off by initializing our container struct
//lpsfTemp = new FXSurface();
lpsfTemp.lpsfSDL = IMG_Load(fpImage.c_str()); // Try to load the requested image
if(lpsfTemp.lpsfSDL != NULL) // If we didn't fail to
{
// Assign some variables for tracking
lpsfTemp.hRefID = hRefID;
lpsfTemp.fpImage = &fpImage;
lpsfTemp.wpxTotal = lpsfTemp.lpsfSDL->w;
lpsfTemp.hpxTotal = lpsfTemp.lpsfSDL->h;
// If a tile width was specified, use it
if(wpxTile != 0)
{
lpsfTemp.wpxTile = wpxTile;
lpsfTemp.hpxTile = hpxTile;
} // Otherwise, assume one tile
else
{
lpsfTemp.wpxTile = lpsfTemp.wpxTotal;
lpsfTemp.hpxTile = lpsfTemp.hpxTotal;
}
// Determine the tiles per row and column for later
cntTileW = lpsfTemp.wpxTotal / lpsfTemp.wpxTile;
cntTileH = lpsfTemp.hpxTotal / lpsfTemp.hpxTile;
// And the total number of tiles
lpsfTemp.cntTiles = cntTileW * cntTileH;
lpsfTemp.lprcTiles = new SDL_Rect[cntTileW*cntTileH];
// So we don't calculate this every time, determine each frame's coordinates and store them
for(int h = 0; h < cntTileH; h++)
{
for(int w = 0; w < cntTileW; w++)
{
cntCurr = (h*cntTileW)+w;
lprcCurr = new SDL_Rect;
lprcCurr->w = lpsfTemp.wpxTile;
lprcCurr->h = lpsfTemp.hpxTile;
lprcCurr->x = w*lpsfTemp.wpxTile;
lprcCurr->y = h*lpsfTemp.hpxTile;
lpsfTemp.lprcTiles[cntCurr] = *lprcCurr;
lprcCurr = NULL;
}
}
// Now acquire our list of animations and set the default
//lpsfTemp.htAnims = new map<int, vector<int> >(*htAnims);
lpsfTemp.htAnims = htAnims;
lpsfTemp.vCurr = lpsfTemp.htAnims.find(FXA_WALK_EAST);
lpsfTemp.fiCurr = lpsfTemp.vCurr->second.begin();
this->m_lstFXObjects.push_back(lpsfTemp);
}
else
{
hRefID = 0;
}
return hRefID;
}
It is precisely as the object is pushed that the error occurs. I've stepped through the code numerous times. Initially, I was only able to tell that my iterators were unable to dereference to the FXSurface object. After using watches to identify the exact memory address that the iterator and list objects pointed to, and dereferencing the address, I noticed the reason for my segfaults: all the values which I put into the original FXSurface were pushed down two memory blocks when the list object copied it!
My process for doing this is simple. I set up a breakpoint at the return statement for CreateCharacter, which gives me a view of lpsfTemp (the FXSurface I later add to the list) and m_lstFXObjects (the list I add it to). I scroll through the members of m_lstFXObjects, which brings me to _M_node, which contains the memory address of the only object I have added so far. I add a watch to this address in the form of (FXSurface)-hex address here-
First, find the address:
(There should be a picture here showing the highlighted _M_node attribute containing the list item's address, but I can't post pictures, and I can only post one URL. The second one is by far more important. It's located at http://www.fauxsoup.net/so/address.jpg)
Next, we cast and deference the address. This image shows both lpsfTemp and the copy in m_lstFXObjects; notice the discrepancy?
http://www.fauxsoup.net/so/dereferenced.jpg - See? All the values are in the correct order, just offset by two listings
I had initially been storing fpImages as a char*, so I thought that may have been throwing things off, but now it's just a pointer and the problem persists. Perhaps this is due to the map<int, vector<int> > I store?
FXSDL has a destructor, but no copy constructor and no assignment operator. Yo you're using naked pointers, but violate the Rule of Three.
I'm not going to look any further.
Use smart pointers to manage resources. Do not put a naked resource into a type, except when that type's only intention is to manage this one resource. From another answer given yesterday:
As a rule of thumb: If you have to manually manage resources, wrap each into its own object.
At a glance, I'd say you're double-deleting lpsfSDL and/or lprcTiles. When you have raw pointers in your structure, you need to follow the rule-of-three (implement copy constructor, assignment operator, and destructor) to properly manage the memory.
These lines look wrong to me:
lprcCurr = new SDL_Rect;
lprcCurr->w = lpsfTemp.wpxTile;
lprcCurr->h = lpsfTemp.hpxTile;
lprcCurr->x = w*lpsfTemp.wpxTile;
lprcCurr->y = h*lpsfTemp.hpxTile;
lpsfTemp.lprcTiles[cntCurr] = *lprcCurr;
lprcCurr = NULL;
lpsfTemp.lprcTiles is a SDL_Rect*. lprcTemp.lprcTiles[cntCurr] is a SDL_Rect. You should be writing this, IMHO:
SDL_Rect tmpRect;
tmpRect.w = lpsfTemp.wpxTile;
tmpRect.h = lpsfTemp.hpxTile;
tmpRect.x = w*lpsfTemp.wpxTile;
tmpRect.y = h*lpsfTemp.hpxTile;
lpsfTemp.lprcTiles[cntCurr] = tmpRect;
Dump the lprcCurr entirely.
Now this code:
lpsfTemp.vCurr = lpsfTemp.htAnims.find(FXA_WALK_EAST);
lpsfTemp.fiCurr = lpsfTemp.vCurr->second.begin();
This is bad. These iterators are invalid as soon as the push_back completes. That push_back is making a copy of lpsfTemp. The map and vector members are going to copy themselves and those iterators will copy themselves but they will be pointing to lpsfTemp's members which are going to be destroyed as soon as CreateCharacter exits.
One way to fix that would be to push_back a FXSurface object at the beginning, use back() to get its reference and operate on that instead of lpsfTemp. Then the iterators would stay consistent and they should stay consistent since you are using a list which does not copy its objects around. If you were using a vector or deque or anything other than a list you would need to manage all those pointers and iterators in the copy constructor and assignment operator.
Another thing: Double and triple check your array bounds when you access that lprcTiles array. Any mistake there and you could be scribbling over who knows what.
I don't know if any of that will help you.