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

 

ImageEn Forum
Profile    Join    Active Topics    Forum FAQ    Search this forumSearch
 All Forums
 ImageEn Library for Delphi, C++ and .Net
 ImageEn and IEvolution Support Forum
 access violation when TImageEnIO Free

Note: You must be registered in order to post a reply.
To register, click here. Registration is FREE!

View 
UserName:
Password:
Format  Bold Italicized Underline  Align Left Centered Align Right  Horizontal Rule  Insert Hyperlink   Browse for an image to attach to your post Browse for a zip to attach to your post Insert Code  Insert Quote Insert List
   
Message 

 

Emoji
Smile [:)] Big Smile [:D] Cool [8D] Blush [:I]
Tongue [:P] Evil [):] Wink [;)] Black Eye [B)]
Frown [:(] Shocked [:0] Angry [:(!] Sleepy [|)]
Kisses [:X] Approve [^] Disapprove [V] Question [?]

 
Check here to subscribe to this topic.
   

T O P I C    R E V I E W
doggybread Posted - Dec 11 2014 : 05:29:20
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.
2   L A T E S T    R E P L I E S    (Newest First)
doggybread Posted - Dec 11 2014 : 13:18:25
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...
w2m Posted - Dec 11 2014 : 10:03:28
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