Mail Archives: djgpp/2000/10/16/05:31:21
Please refer to my questions throughout the code...
> struct CEnemy
> {
> short int ID;
> BITMAP *sprite;
> float x,
> y,
> xvel,
> yvel;
> bool hit, type;
> short int HP, life;
>
> CEnemy(int ID, int a, int b, int function);
> ~CEnemy();
>
> void (*draw)(BITMAP *bitmap, CEnemy *e); // pointer to function that
> draws bullet
> bool (*routine)(CEnemy *e); // pointer to function for updating
bullet
> short int var1, var2, var3, var4; // uses depend on bullet type
> }; vector<CEnemy*> E(0);
Since this is quite a complicated struct (constructors, functions, et. al.),
would it not be better calling it a class?
> const int GTop = 500;
> const int GBot = 501;
>
> /* Prototypes for enemy behavior
> ********************************************/
> bool Test(CEnemy *e);
>
> /* Constructor
> **************************************************************/
> CEnemy::CEnemy(int ID, int a, int b, int function):
> x(a), y(b), life(0)
> {
What this tells me is that your struct is descended from classes x, y, and
life, and you are calling those constructors!
Instead, I think you should have (as the first lines of your constructor):
x = a;
y = b;
life = 0;
> switch(function)
> {
> case 0: routine = Test;
> switch(ID)
> {
> case GTop: sprite = create_bitmap(200, 190);
> return;
> case GBot: sprite = create_bitmap(200, 160);
> return;
> }
> }
> }
>
> CEnemy::~CEnemy()
> {
> destroy_bitmap(sprite);
> }
>
>
> The problem is in the destructor. If I attempt to empty the vector,.....
>
>
> vector<CEnemy*>::size_type Esize = E.size();
>
> for(int a = 0 ; a < Esize ; a++){
> delete (E.end() - 1);
I am not sure why you're trying to delete what appears to be an integer
result here...
> E.pop_back();
> }
>
> I get a crash at runtime, which follows......
>
> Shutting down Allegro
> Exiting due to signal SIGSEGV
> Page fault at eip=0006a034, error=0006
> eax=ff8bfd88 ebx=001321bc ecx=001321c4 edx=001321c0 esi=00131d9c
> edi=00131d98
> ebp=00131d20 esp=00131d14 program=C:\CHRIS'~1\VERTIC~2\TRANSF~1.EXE
> cs: sel=00af base=83098000 limit=ffd67fff
> ds: sel=00b7 base=83098000 limit=ffd67fff
> es: sel=00b7 base=83098000 limit=ffd67fff
> fs: sel=00c7 base=00000000 limit=0010ffff
> gs: sel=00c7 base=00000000 limit=0010ffff
> ss: sel=00b7 base=83098000 limit=ffd67fff
> App stack: [00131f14..000b1f14] Exceptn stack: [000b1e6c..000aff2c]
>
> Call frame traceback EIPs:
> 0x0006a034 _free+28
> 0x00066b33 ___builtin_delete+23, line 0 of new2.cc
> 0x00002f63 ___9TestLevel+403, line 39 of TFAA.cpp
> 0x00005158 _InitLevel__Fi+44, line 707 of TFAA.cpp
> 0x00005289 _PlayGame__Fi+161, line 728 of TFAA.cpp
> 0x00003311 _main+233, line 185 of TFAA.cpp
> 0x000695d2 ___crt1_startup+178
>
> I'm pretty sure it's the destructor that's doing this, because eliminating
> the delete or the destroy_bitmap() seems to fix it, but I see nothing
wrong
> with it (not exactly complex, is it?). And in the call frame traceback;
what
> is new2.cc? This file is nowhere to be found on my hard drive. Hopefully
> someone here can help me with this; it's driving me batty. Thank you.
You don't have the compiler and library sources installed, I expect.
new2.cc is probably the part of the compiler (or library, I can't remember
which) that tells how the new and delete operators work.
- Raw text -