[fpc-pascal]Exception w/ Freemem()

Jon Sawyer bq at badquanta.net
Fri Apr 11 07:32:48 CEST 2003


W/ the following code whenever I call DeAllocate() I get the following error:
An unhandled exception occurred at 0x0806268A :
Invalid pointer operation
  0x0806268A
  0x08061FB0
  0x0805AAF7
  0x08065D17
  0x08048567


I've been able to track it to the FreeMem() line, but I don't understand why 
its doing it..

I've got the folowing code:

Function    tQSurface.Allocate(iWidth, iHeight: Word): Boolean;
Begin
  {Check for Mem}
  If MaxAvail > (iWidth*iHeight*SizeOf(tQPixel)) then
  Begin
    {$IfDef QDebug}
      WriteDebug('Allocated(): OK!');
    {$EndIf}
    If Allocated then DeAllocate;
    GetMem(fBitmap, iWidth*iHeight*SizeOf(tQPixel));
    fWidth  := iWidth;
    fHeight := iHeight;
    Allocate := TRUE;
  end
  else
  Begin
    {$IfDef QDebug}
      WriteDebug('Allocate(): Not Enough Memory');
    {$EndIf}
    Allocate := False;
  End;
end;

Procedure   tQSurface.DeAllocate;
Begin
  If fBitmap <> nil then
  Begin
    FreeMem(fBitmap, fWidth*fHeight*SizeOf(tQPixel));
  end;
end;



Thanks in advanced for any help/advice..



More information about the fpc-pascal mailing list