delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2001/03/10/22:11:45

Message-ID: <3AAAE89C.6050002@operamail.com>
From: Sahab Yazdani <sahaby AT operamail DOT com>
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???
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<lbD;xCounter++)
       	mem_ptr[counter+xCounter]=(unsigned char) fgetc(in);
       if (lbD%4!=0) {
	      for (xCounter=0;xCounter<4-(lbD%4);xCounter++)
    	   	fgetc( in ); // Burn the 4-byte buffer
       }
	}
	
	fclose( in );
// ^^^^^^^^^^^^^^^^^ this line crashes according to SYMIFY
	
	return true;
}

[INTERESTING NOTE: RHIDE has decided that 'in' is a keyword and hilights it]

as you can see the code is part of a class, but that shouldn't really be 
that important should it??

SECOND problem:  calls to new and delete are causing erratic problems, 
sometimes they work and other times they crash the program, this 
seemingly occurs at random.  this one is most likely due to bad coding, 
but I can't be sure because of the fclose problem....

specs: I just reinstalled DJGPP using Zip-Picker in the vain hope that 
this might fix the problems, well now I have an updated version of DJGPP :-)

PS.  Does anybody know where to get NASM?  Their site has a download, 
but it is just documentation.  (Latest Version is 0.98).

PPS.  On a side note, RHIDE has decided that whenever I go to 
File|Open... it defaults to the djgpp/bin/ directory...  this is really 
annoying as my working directories are nowhere near there...

-- 
***********************************************************
* Sahab Yazdani * "Wizard's Third Rule: Passion rules     *
* Thornhill S.S * Reason" - Kolo's Journal                *
***********************************************************
* http://pheonixsoft.virtualave.net/                      *
***********************************************************

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019