About Store Forum Documentation Contact



Post Reply 
Memory access error, in derived classes
Author Message
McTomas Offline
Member

Post: #1
Memory access error, in derived classes
Hello everyone

Well i'm having a big problem in manipulating memory blocks. I'll start from the beginning with the exemples of what i'm trying to fo..

I create an base enemy class and a derived enemy class.
Code:
struct Enemy {
Int pos;
Int type;

virtual void update() {}
}

struct Boss : Enemy {

virtual void update() {pos++;}
}

And i have an enemyManager where I create and manipulate my enemys, and where I have my enemys memory block.

Code:
Memb <Enemy*> enemies

void createEnemy() {

Enemy *_enemy = enemies.New();
_enemy->pos = 0;
}

the game compiles with no errors and no warnings

but when i'm running the game and I create an enemy it breaks and give me and error of memory access violation in here '_enemy->pos = 0;'

I have no ideia why it gives me that error, but i have no clue how to solve it... :?



I'll take advantage of this topic to ask anothe question... how can i have a 2D view in my camera?
Because the camera viewport is a perspective viewport with one point reference in a 3D world, how can i change it to a parallel viewport with no focus point?

best regards


McTomas
08-24-2009 05:21 PM
Find all posts by this user Quote this message in a reply
menajev Offline
Member

Post: #2
Re: Memory access error, in derived classes
McTomas Wrote:
Code:
Memb <Enemy*> enemies

void createEnemy() {

Enemy *_enemy //this is pointer
= enemies.New(); //and this makes pointer too
_enemy->pos = 0; //_enemy is pointing to nowhere
}
Correct code should look like that:
Code:
Enemy* enemy = new Enemy;
enemies.add(enemy);
08-24-2009 05:55 PM
Find all posts by this user Quote this message in a reply
Esenthel Offline
Administrator

Post: #3
Re: Memory access error, in derived classes
you can also just use:
Memb<Enemy> or (Memx<Enemy> if you need constant memory addressess for objects)
08-24-2009 09:40 PM
Find all posts by this user Quote this message in a reply
Post Reply