ImageEn for Delphi and C++ Builder ImageEn for Delphi and C++ Builder

 

ImageEn Forum
Profile    Join    Active Topics    Forum FAQ    Search this forumSearch
Forum membership is Free!  Click Join to sign-up
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 ImageEn Library for Delphi, C++ and .Net
 ImageEn and IEvolution Support Forum
 access violation when TImageEnIO Free
 New Topic  Reply to Topic
Author Previous Topic Topic Next Topic  

doggybread

2 Posts

Posted - Dec 11 2014 :  05:29:20  Show Profile  Reply
enviroment: Delphi Xe7 up1 with ImageEn 5.2.0

I'm building a service application which can respond image stream via TIDHTTPServer. And I load the image stream from file with TImageEnIO.


function DoLoadStream(const vFileName:String; var vOutStream:TStream; thumbsize:Integer=100):Boolean;
var
  ImageEnIO1:TImageEnIO;
  ImageEnProc1: TImageEnProc;
begin
ImageEnIO1:= TImageEnIO.Create(nil);
ImageEnProc1:= TImageEnProc.Create(nil);
try
  ImageEnIO1.LoadfromFile(vFileName);
  ImageEnProc1.AttachedIEBitmap := ImageEnIO.IEBitmap;
  ImageEnProc1.Resample(thumbsize, thumbsize,
    TResampleFilter.rfTriangle, true);
  ImageEnIO1.SaveToStream(vOutStream, ImageEnIO1.Params.FileType);
finally
  ImageEnProc1.Free;
  ImageEnIO1.Free;
end;
end;


Here is the issue. ImageEnIO1.Free will cause Access violation sometime, but not all the time. Isn't the code above thread safe?

I removed the ImageEnProc part and the issue remain.

w2m

USA
1990 Posts

Posted - Dec 11 2014 :  10:03:28  Show Profile  Reply
I do not know about using ImageEn with services, but try this:
function DoLoadStream(const vFileName: String; var vOutStream: TStream;
  thumbsize: Integer = 100): Boolean;
var
  ImageEnIO1: TImageEnIO;
  ImageEnProc1: TImageEnProc;
begin
  ImageEnIO1 := TImageEnIO.Create(nil);
  try
    ImageEnProc1 := TImageEnProc.Create(nil);
    try
      ImageEnIO1.LoadfromFile(vFileName);
      ImageEnProc1.AttachedIEBitmap := ImageEnIO1.IEBitmap;
      ImageEnProc1.Resample(thumbsize, thumbsize,
        TResampleFilter.rfTriangle, true);
      ImageEnIO1.SaveToStream(vOutStream, ImageEnIO1.Params.FileType);
    finally
      ImageEnProc1.Free;
    end;
  finally
    ImageEnIO1.Free;
  end;
end;


You had:
ImageEnProc1.AttachedIEBitmap := ImageEnIO.IEBitmap;
When it should be:
ImageEnProc1.AttachedIEBitmap := ImageEnIO1.IEBitmap;

Bill Miller
Adirondack Software & Graphics
Email: w2m@hughes.net
EBook: http://www.imageen.com/ebook/
Custom Commercial ImageEn Development
Go to Top of Page

doggybread

2 Posts

Posted - Dec 11 2014 :  13:18:25  Show Profile  Reply
hi bill, thanks for your reply and pointing out the mistake in my code.
The name of the variable in the project file is correct, otherwise it is impossible to compile and run. but thanks anyway.
I've probably found the key reason somewhere else, using global variables without Critical Section lock...
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
Jump To: