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
 EOutOfMemory
 New Topic  Reply to Topic
Author Previous Topic Topic Next Topic  

dave.sellers

United Kingdom
17 Posts

Posted - Mar 04 2013 :  04:20:43  Show Profile  Reply
ImageEn 4.3 Delphi 7

Having hit this problem in a real application, have stripped back to most basic test to reproduce

Simply drop TImageEnMView and TImageEnView on form and execute:

procedure TForm1.Starttest1Click(Sender: TObject);
var
i : integer;
begin
ImageEnMView1.Clear;
ImageEnMView1.FillFromDirectory(ExtractFilePath(Application.ExeName) + 'TestImages');
for i := 0 to ImageEnMView1.ImageCount -1 do
begin
Self.Caption := format('Image #%d: %s', [i, ImageEnMView1.ImageFileName[i]]);
Application.ProcessMessages;
ImageEnMView1.SelectedImage := i;
ImageEnView1.Clear;
ImageEnMView1.CopyToIEBitmap( i, ImageEnView1.IEBitmap );
end;
end;

After ~30 images displayed, EOutOfMemory exception occurs.
Images are scanned images, 4-8MB in size, typically 6.5k x 4.5k pixels.
Tried changing TImageEnMView.ImageCacheSize from default 10 to 5 and then to 2 but this just seems to alter how many images it displays before it blows up.
According to task manager, the application is only using ~250MB when it blows up which seems odd

Is there something wrong with the way I'm doing this or perhaps the problem is the files themselves?

I've uploaded the test project and the image files, so if anybody would like to try for themselves you can download: http://reddoorsoftware.co.uk/DaveTest.zip

I'm using Eurekalog and its .elf file is included. It consistently shows the last line in the call stack to be in TIEFileBuffer.Map (line 24843) which is: getmem(result, InSize);

Any help/suggestions welcome.

Dave

w2m

USA
1990 Posts

Posted - Mar 04 2013 :  07:42:21  Show Profile  Reply
You are getting outofmemory exception because you are processing files in ImageEnMView that have not been loaded yet. FillFromDirectory is threaded so you trying to process files that are not loaded.

Fixing this is simple. Just begin processing files after they all have been loaded using the OnAllDisplayed event. This event is executed when all images are loaded and displayed.

In my test all 65 of the files are processed with no exceptions:

procedure TForm1.Starttest1Click(Sender: TObject);
var
  iPath: string;
begin
  ImageEnMView1.Clear;
  iPath := ExtractFilePath(Application.ExeName) + 'TestImages';
  StatusBar1.Panels[0].Text := iPath;
  ImageEnMView1.FillFromDirectory(iPath);
end;

procedure TForm1.ImageEnMView1AllDisplayed(Sender: TObject);
var
  i: integer;
begin
  StatusBar1.Panels[2].Text := 'Files: ' + IntToStr(ImageEnMView1.ImageCount);
  for i := 0 to ImageEnMView1.ImageCount - 1 do
  begin
    Self.Caption := Format('Image #%d: %s', [i, ImageEnMView1.ImageFileName[i]]);
    StatusBar1.Panels[1].Text := ExtractFileName(ImageEnMView1.ImageFileName[i]);
    ImageEnMView1.SelectedImage := i;
    ImageEnMView1.CopyToIEBitmap(i, ImageEnView1.IEBitmap);
    ImageEnView1.Update;
    StatusBar1.Panels[3].Text := 'File: ' + IntToStr(i+1);
    Application.ProcessMessages;
  end;
end;

William Miller
Email: w2m@frontiernet.net
EBook: http://www.imageen.com/ebook/
Apprehend: http://www.frontiernet.net/~w2m/index.html
Go to Top of Page

dave.sellers

United Kingdom
17 Posts

Posted - Mar 04 2013 :  12:14:48  Show Profile  Reply
Hi William

That makes sense. In the light of that I will revisit the real application tomorrow - it doesn't use FillFromDirectory but fills the list manually using a bunch of calls to ImageEnMView1.MIO.LoadFromFile. I expect the underlying cause is much the same - my trying to copy from the bitmap before it's ready.

I shall also take a look at your EBook tomorrow.

Thanks for your help.

Dave
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
Jump To: