Message-ID: <3AAAE89C.6050002@operamail.com> From: Sahab Yazdani Organization: PheonixSoft Interactive User-Agent: Mozilla/5.0 (Windows; U; Win98; en-US; 0.8.1) Gecko/20010307 X-Accept-Language: en MIME-Version: 1.0 Newsgroups: comp.os.msdos.djgpp Subject: fclose??? Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit Lines: 107 Date: Sat, 10 Mar 2001 21:53:16 -0500 NNTP-Posting-Host: 149.99.18.150 X-Complaints-To: abuse AT sprint DOT ca X-Trace: newscontent-01.sprint.ca 984279550 149.99.18.150 (Sat, 10 Mar 2001 21:59:10 EST) NNTP-Posting-Date: Sat, 10 Mar 2001 21:59:10 EST To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Reply-To: djgpp AT delorie DOT com Hello everybody, i'm having a whole string of strange problems which seem to be very loosely interconnected. The first is that my program is crashing with a call to fclose. I've checked the pointers and they seem to be fine (as far as I can tell). The code is supposed to open a Windows Bitmap (BMP) file and store it in an linear array: bool GResourceWindowsBitmap::Load() { FILE *in; int counter, xCounter; int bitSize; in = fopen( filename, "rb" ); if (in==NULL) return false; fread( &header, sizeof( BMPHeader ), 1, in ); if ( ( header.Type[0]!='B' ) || ( header.Type[1]!='M' ) ) { fclose( in ); return false; } if ( header.Compression!=0 ) { fclose( in ); return false; } // Set some internal variables version = 0; // File Format Version (None for Windows Bitmaps) length = header.Width; width = header.Height; bitDepth = header.BitCount; bitSize = length*width*(bitDepth>>3); mem_ptr = new unsigned char[bitSize]; if (mem_ptr==NULL) { fclose( in ); return false; } allocated=true; if (bitDepth<8) { delete mem_ptr; fclose( in ); return false; } if (bitDepth==8) { GRGB rgb; palette = new GPalette( GRGB( 0, 0, 0 ) ); for ( counter = 0; counter< 256; counter++ ) { fread( &rgb, sizeof( GRGB ), 1, in ); fgetc( in ); // Ignore Alpha Channel rgb.red>>=2; rgb.green>>=2; rgb.blue>>=2; palette->SetColour( counter, rgb ); } } fseek( in, header.OffBits, SEEK_SET ); int lbD = length * (bitDepth>>3); for (counter=bitSize-lbD;counter>=0;counter-=lbD) { for (xCounter=0;xCounter