I have a bullet class defined in a header file as such:
#ifndef BULLETS_H
#define BULLETS_H
#define MAX_BULLETS 100
#define MAX_LIFE 1000
class bullet_data
{
public:
int bullet_object;
int bullet_exists;
int bullet_strike;
int bullet_life;
};
class bullets
{
private:
bullet_data list[MAX_BULLETS];
int max_reload_time;
int reload_timer;
int current_bullet;
float bullet_size;
float bullet_speed;
public:
//constructor methods
bullets (int reload_time, float bullet_size, float bullet_speed);
//mutator methods
void update_bullets (void);
void fire_bullet (void);
void destroy_bullet (int);
};
#endif
and the code for the fire_bullet function is:
void bullets::fire_bullet (void)
{
if (reload_timer <= 0)
{
if (current_bullet >= MAX_BULLETS)
current_bullet = 0;
while (dbObjectExist (list[current_bullet].bullet_object))
list[current_bullet].bullet_object++;
dbMakeObjectSphere (list[current_bullet].bullet_object, bullet_size);
dbPositionObject (list[current_bullet].bullet_object, dbCameraPositionX (), dbCameraPositionY (), dbCameraPositionZ ());
dbSetObjectToCameraOrientation (list[current_bullet].bullet_object);
list[current_bullet].bullet_exists = 1;
list[current_bullet].bullet_life = MAX_LIFE;
current_bullet++;
reload_timer = max_reload_time;
}
}
I call it in my main program like so:
while (LoopGDK ())
{
dbControlCameraUsingArrowKeys (0, 5.0f, 5.0f);
bullet_list.update_bullets ();
if (dbMouseClick () == 1)
bullet_list.fire_bullet ();
dbSync ();
}
It keeps triggering a breakpoint at the line where i try to determine the free objects using dbObjectExist (). It says
"Unhandled exception at 0x004a7e2b in program.exe: 0xC0000005: Access violation reading location 0xccdfc564." Can anyone tell me what the problem is?
If you need to see the rest of the class to get more info, please let me know. this is a real pain.