Recent

Author Topic: Why does this seg fault bgrareplace?  (Read 2255 times)

vonskie

  • Full Member
  • ***
  • Posts: 184
Why does this seg fault bgrareplace?
« on: September 13, 2017, 05:56:01 pm »
Why does this Seg fault here


>>>>bgrareplace(bmp,newimage);
       
Here is the code

Am I using bgrareplace correctly?


bmp := TBGRABitmap.Create;
        bmp.LoadFromfile(imageselected.Text);

        try
        newimage := TBGRABitmap.Create(screen.Width, screen.Height, BGRABlack);
        newimage.PutImage(0, 0, bmp, dmDrawWithTransparency);
        bgrareplace(bmp,newimage);
        finally
        newimage.free;
        end;

        bmp.SaveToFile(filepath + 'wallpaper.bmp');
        bmp.free;

 Logged

vonskie

  • Full Member
  • ***
  • Posts: 184
Re: Why does this seg fault bgrareplace?
« Reply #1 on: September 13, 2017, 08:35:03 pm »






If I do this

bgrareplace(bmp,newimage as TBGRABitmap);

It gets past that error but gets a segfault on the save.

        bmp.SaveToFile(filepath + 'wallpaper.bmp');

If I save inside the try block it works though?

Why?


        bmp := TBGRABitmap.Create;
        bmp.LoadFromfile(imageselected.Text);

        try
        newimage := TBGRABitmap.Create(screen.Width, screen.Height, BGRABlack);
        newimage.PutImage(0, 0, bmp, dmDrawWithTransparency);
        bgrareplace(bmp,newimage as TBGRABitmap);
        finally
        newimage.free;
        end;

        bmp.SaveToFile(filepath + 'wallpaper.bmp');
        bmp.free;

circular

  • Hero Member
  • *****
  • Posts: 4220
    • Personal webpage
Re: Why does this seg fault bgrareplace?
« Reply #2 on: September 18, 2017, 07:17:22 pm »
BGRAReplace(dest, source) will free the destination pointer and copy the source pointer.

It is equivalent to :

Code: Delphi  [Select][+][-]
  1. temp := dest;
  2. dest := source;
  3. temp.Free;

So don't call source.Free otherwise you won't have anything left.
Conscience is the debugger of the mind

 

TinyPortal © 2005-2018