[fpc-pascal]Exception w/ Freemem()

Jon Sawyer bq at badquanta.net
Fri Apr 11 17:37:51 CEST 2003

On Thursday 10 April 2003 23:55, Jonas Maebe wrote:
> On vrijdag, apr 11, 2003, at 07:32 Europe/Brussels, Jon Sawyer wrote:
> >   If MaxAvail > (iWidth*iHeight*SizeOf(tQPixel)) then
> >   Begin
> Note that you should leave this line out. MaxAvail only indicates how
> much of the memory that's currently allocated to your application is
> still free. Once that memory is full and you allocate more, the RTL
> will ask the OS to grow the heap of your program. Once memory is
> exhausted (though this can happen long after you've used all physical
> memory in the computer, since the OS will use swapping to give you
> more), you will get a run time error 204. To catch this and make sure
> your program doesn't stop then, you have to use exceptions (uses
> sysutyils; and a try..except block, see the manual for more info).
 Thank you.  I will look into that and try it out.

> These kind of problems usually are due to some memory corruption,
> like writing past the end of an allocated memory block,
> which can then destroy the chain of free blcoks handled 
> in GetMem/FreeMem functions.

> I would bet that simply calling Allocate and Deallocate 
> will not generate your exception...

> Try to compile your program with '-ghl' option.
> (and also the RTL sources if you have them,
> just use 'make OPT=-ghl' in your RTL source directory)
> This might help you to find out what's is going wrong.

> Unless you can give aa full source code and 
> a detailed suite of operations to do to reproduce the bug
> (if your program is interactive)
> it will be very difficult to help you more....

I is absolutly possible for me to give a full bug report but it is most likely 
a bug in my own code.   I'll have to check my GL routines to make sure that
they are not writing past the end of the allocated chunk of memory.  

I'm using Pointer Math to write to the memory: ie 
pQPixel(fBitmap)[(fWidth*iY)+(iX-1)] := MyPixel; {ect..}
^-- Is there anything wrong with this algorithim?

Thats the only algorithim I have implemented at the moment that writes the
memory surface.

More information about the fpc-pascal mailing list