From: "23yrold3yrold" Newsgroups: comp.os.msdos.djgpp Subject: destroy_bitmap in destructor Date: Sun, 15 Oct 2000 13:21:37 -0500 Lines: 101 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 5.00.2919.6600 X-MimeOLE: Produced By Microsoft MimeOLE V5.00.2919.6600 NNTP-Posting-Host: spamkiller Message-ID: <39e9f547_4@spamkiller.newsfeeds.com> X-Comments: This message was posted through Newsfeeds.com X-Comments2: IMPORTANT: Newsfeeds.com does not condone, nor support, spam or any illegal or copyrighted postings. X-Comments3: IMPORTANT: Under NO circumstances will postings containing illegal or copyrighted material through this service be tolerated!! X-Report: Please report illegal or inappropriate use to You may also use our online abuse reporting from: http://www.newsfeeds.com/abuseform.htm X-Abuse-Info: Please be sure to forward a copy of ALL headers, INCLUDING the body (DO NOT SEND ATTACHMENTS) Organization: Newsfeeds.com http://www.newsfeeds.com 73,000+ UNCENSORED Newsgroups. To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Reply-To: djgpp AT delorie DOT com I've been having a lot of trouble with this, so I'm gonna post a fair bit of code and errors in the hope that SOMEONE can tell me what I'm doing wrong. Here's a snippet of code for a struct for an enemy in a simple game I'm making: 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 E(0); 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) { 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::size_type Esize = E.size(); for(int a = 0 ; a < Esize ; a++){ delete (E.end() - 1); 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. Chris