* * *

Author Topic: Why does this Seg fault? bgrareplace  (Read 574 times)

vonskie

  • Full Member
  • ***
  • Posts: 127
Why does this Seg fault? bgrareplace
« on: September 13, 2017, 04:55:48 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;


lainz

  • Hero Member
  • *****
  • Posts: 2014
Re: Why does this Seg fault? bgrareplace
« Reply #1 on: September 15, 2017, 07:37:19 pm »
You can upload a small program that reproduces the error?

vonskie

  • Full Member
  • ***
  • Posts: 127
Re: Why does this Seg fault? bgrareplace
« Reply #2 on: September 15, 2017, 11:50:43 pm »
i think bgrareplace automatically frees newimage so the finally newimage.free was an issue.


lainz

  • Hero Member
  • *****
  • Posts: 2014
Re: Why does this Seg fault? bgrareplace
« Reply #3 on: September 16, 2017, 12:38:38 am »
i think bgrareplace automatically frees newimage so the finally newimage.free was an issue.

BGRAReplace is designed to replace the same image, like

BGRAReplace(bmp, bmp.Resample(...) as TBGRABitmap);

Because some methods creates a new bitmap, usually you want to be the same bitmap as output, like when you do, for example, resample, blur and other filters.

circular

  • Hero Member
  • *****
  • Posts: 2602
    • Personal webpage
Re: Why does this Seg fault? bgrareplace
« Reply #4 on: September 17, 2017, 07:10:43 pm »
Indeed. BGRAReplace frees the destination image.
Conscience is the debugger of the mind

 

Recent

Get Lazarus at SourceForge.net. Fast, secure and Free Open Source software downloads Open Hub project report for Lazarus