Sign in to follow this  
raptorstrike

I Know theres a problem (i just dont know how to fix it)

Recommended Posts

ok what this function is doing is (wow this is complicated) ok its reading in a text file that has some atributes of the object, then puting it at posistion 50,50 and placing that object in the back of a vector i think the problem is in the enemy constructor but ill post more code then that
void Level::run(int LVL_NUM,char* Master_Enemy_List[])
{  

        Enemy* New_Enemy = new Enemy(Master_Enemy_List[0],50,50,&this->Enemy_Vector);// master list is the .txt files that the constructor reads from
        this->Enemy_Vector.push_back(New_Enemy);
        this->Respawn++;
    return;
};        



Enemy::Enemy(char* File_Name, int x, int y,vector<Enemy*> *V_Enemy)
{
    FileName = File_Name;
    R_Enemy.x = x;
    R_Enemy.y = y;
    ifstream fin;
    this->Name = "";
    fin.open(FileName);
    getline(fin, Name);
    fin >> this->Life;
    getline(fin, Image);
    fin >> this->Weapon_ID; // index to a weapon array;
    fin >> this->Speed;
    fin >> this->ID;//index to enemy array
    fin.close();
    V_Enemy->push_back(this);
};        



//part of source
char* Master_Enemy_Files[] = {"Enemy_One.txt"}; 
//later
I_Enemy = SDL_LoadBMP(Enemy_List[One->Enemy_Vector[i]->ID]);
             TempRectBlit(I_Enemy,screen,One->Enemy_Vector[i]->R_Enemy);
             One->Enemy_Vector[i]->R_Enemy.x -= One->Enemy_Vector[i]->Speed;



lol oops ok the problem is that this image is sapposed to render and move accross the screen briefly (yes thats it for now) and it isnt i ran to debugger and got 2 segmentation faluts but it wont point our were they are and since these are the only 2 functions that i have changed today its gotta be them also when commenting out the run() it runs fine

Share this post


Link to post
Share on other sites
I can almost gaurantee the problem is caused by mixing pointer and array type parameters. Use pointer-types exclusively. You're probably not deleting the new'd object in run.

Share this post


Link to post
Share on other sites
acctuall i think the problem is that i was treating this

const char* Enemy_List[] = {"Enemy.bmp"};

as this

const char* Enemy_List[][50] = ("Enemy.bmp"};

would a vector of const char* do the job?

i want each "blalblablal" to be treated as ONE thing not a whole bunch of chars but i have to use const char* for file names (i cant use strings) so would that suffice??

Note: i put this alot for clarity and if there are external variables with simaler names

[Edited by - raptorstrike on November 8, 2004 9:52:22 PM]

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this