Highlighted

Adobe AIR Application crashes when trying to import around 700 high resolution images

Community Beginner ,
Feb 22, 2018

Copy link to clipboard

Copied

Hi,

I am trying to import more than 700 high resolution images in my Adobe AIR app. I am using flash builder 4.6 for development, and while debugging it works fine. The application seems to crash when a release build(.air or .exe or .dmg file) is made and run after installation.

Below is my code for importing images.

public function ImportImages(event:*):void

{

     var file:File = File.userDirectory;

     file.browseForOpenMultiple("Select Images",[MgrYSIPath.imageFlter]);

     file.addEventListener(FileListEvent.SELECT_MULTIPLE,saveImportImage);

     file.addEventListener(Event.CANCEL, cancelExport);

}

private function saveImportImage(event:FileListEvent):void

{

     setRank();

     SaveImageFiles(event.files);

}

private var tm:Number = 0;

private var ImgOperation:LBImportImageOperation;

private function SaveImageFiles(files:Array):void

{

     tm = getTimer();

     TBLImages_DAO.Instance.tempList.removeAll();

     ImgOperation = new LBImportImageOperation();

     //ImgOperation.SaveImportFilesFromNewJob(Rank,files,SaveCompliteHandler);

     ImgOperation.SaveImportFilesFromNewJob(Rank,files,SaveCompliteImportHandler);

     ImgOperation=null;

}

I am clueless about how to troubleshot this issue as it works fine in debugger and crashes in app.

Please help!!

Thanks in advance

TOPICS
Development

Views

353

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more

Adobe AIR Application crashes when trying to import around 700 high resolution images

Community Beginner ,
Feb 22, 2018

Copy link to clipboard

Copied

Hi,

I am trying to import more than 700 high resolution images in my Adobe AIR app. I am using flash builder 4.6 for development, and while debugging it works fine. The application seems to crash when a release build(.air or .exe or .dmg file) is made and run after installation.

Below is my code for importing images.

public function ImportImages(event:*):void

{

     var file:File = File.userDirectory;

     file.browseForOpenMultiple("Select Images",[MgrYSIPath.imageFlter]);

     file.addEventListener(FileListEvent.SELECT_MULTIPLE,saveImportImage);

     file.addEventListener(Event.CANCEL, cancelExport);

}

private function saveImportImage(event:FileListEvent):void

{

     setRank();

     SaveImageFiles(event.files);

}

private var tm:Number = 0;

private var ImgOperation:LBImportImageOperation;

private function SaveImageFiles(files:Array):void

{

     tm = getTimer();

     TBLImages_DAO.Instance.tempList.removeAll();

     ImgOperation = new LBImportImageOperation();

     //ImgOperation.SaveImportFilesFromNewJob(Rank,files,SaveCompliteHandler);

     ImgOperation.SaveImportFilesFromNewJob(Rank,files,SaveCompliteImportHandler);

     ImgOperation=null;

}

I am clueless about how to troubleshot this issue as it works fine in debugger and crashes in app.

Please help!!

Thanks in advance

TOPICS
Development

Views

354

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Feb 22, 2018 0
Advocate ,
Feb 23, 2018

Copy link to clipboard

Copied

In what case would you need to load 700 images? Could it be that you are going at this the wrong way to start with? I have an app that does something similar with around 200 000 images but it only loads the ones I need to display. In your case I would store the reference of those 700 files, then only load them when they show up on screen.

Yes AIR on desktop has memory limits that can cause crashes and in your case you might very well run into that.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Feb 23, 2018 0
Community Beginner ,
Feb 23, 2018

Copy link to clipboard

Copied

Your question is right. The application is importing more than 700 images and converting them into low resolution and mid resolution images that would be used to display the thumbnails. The actual images can be referenced later when needed.

The strange thing is that when I am importing a directory which consists of more than 700 images, the application works fine. But when selecting 700 images by multiple files select app crashes.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Feb 23, 2018 0
Community Beginner ,
Feb 23, 2018

Copy link to clipboard

Copied

To make my point clear, my application has both the features. 1. Import image folder 2. Import images

1. Import Image Folder Code:

public function ImportFolder(event:LightBoxImageEvent):void

{

try{

var directory:File = File.userDirectory;

directory.browseForDirectory("Select Directory");

directory.addEventListener(Event.SELECT, saveImportFolder, false, 0, true);

directory.addEventListener(Event.CANCEL, cancelExport, false, 0, true);

}

catch(error:*) {}

}

private function saveImportFolder(event:Event):void

{

var directory:File = File.userDirectory;

    directory = event.target as File;    

    var files:Array = new Array();

    for each (var file:File in directory.getDirectoryListing())

    {   

    if (!file.isDirectory &&  MgrYSIPath.imageFlterObject.hasOwnProperty(file.extension.toLowerCase()));

          files.push(file);

    }

SaveImageFiles(files);

}

private function SaveImageFilesForDrag(files:Array):void

{

tm = getTimer();

var ImgOperation:LBImportImageOperation = new LBImportImageOperation();

//ImgOperation.SaveImportFiles(Rank,files,SaveCompliteHandler);

ImgOperation.SaveImportFiles(Rank,files,SaveCompliteImportHandler);

//ImgOperation=null;

}

2. Import Images Code:

public function ImportImages(event:*):void

{

     var file:File = File.userDirectory;

     file.browseForOpenMultiple("Select Images",[MgrYSIPath.imageFlter]);

     file.addEventListener(FileListEvent.SELECT_MULTIPLE,saveImportImage);

     file.addEventListener(Event.CANCEL, cancelExport);

}

private function saveImportImage(event:FileListEvent):void

{

     setRank();

     SaveImageFiles(event.files);

}

private var tm:Number = 0;

private var ImgOperation:LBImportImageOperation;

private function SaveImageFiles(files:Array):void

{

     tm = getTimer();

     TBLImages_DAO.Instance.tempList.removeAll();

     ImgOperation = new LBImportImageOperation();

     //ImgOperation.SaveImportFilesFromNewJob(Rank,files,SaveCompliteHandler);

     ImgOperation.SaveImportFilesFromNewJob(Rank,files,SaveCompliteImportHandler);

     ImgOperation=null;

}

I am clueless why the #1Import Image Folder works fine while #2import Images crashes.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Feb 23, 2018 0
Advocate ,
Feb 23, 2018

Copy link to clipboard

Copied

The code you are showing is hardly relevant to your case unless you can show that your app crashes even when commenting out that line: " ImgOperation.SaveImportFilesFromNewJob", if it's not the case then what's relevant is whatever is going on inside this: " ImgOperation.SaveImportFilesFromNewJob".

But even so you are taking the very easy road with that code: load everything, make thumbnails and be done with it. The app in that case has to request ton of memory from the OS for an operation that really should be sequential and probably in background (worker).

The way I handle this personally is store all file references (and this works with 200k high quality images), then create batches of predetermined sizes (let's say 100), create thumbnails for each batch and making sure to release all memory and run batches until all files are handled with and run everything in a worker.

Not only this process is fast but it allows me to control memory consumption and never block my UI even with gigantic number of files and of course no crashes.

In your case your app requests a one time memory increase of: 700 * image.memorysize * 700 * image.memorysize * thumbnailratio (bytes)

With batches and workers an all time max would be: batch_number * image.memorysize * batch_number * image.memorysize * thumbnailratio (bytes)

With memory cleanup in between batches that's a huge difference.

Another point, do you really display those 700 thumbnails at once? If not then same principle applies, only do the ones you display and do the others on the fly when they need to be displayed.

At the end it's really all about memory consumption (that's what I think your problem is) unless you can really show your problem has nothing to do with memory.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Feb 23, 2018 0
Community Beginner ,
Feb 24, 2018

Copy link to clipboard

Copied

Thanks for your response.

I think I have to micro-analyse which portion of my code is crashing the application. Then I can check the memory consumption. Since it's working fine in debugger, I have to use the log file for release build troubleshooting. I will keep updating as I proceed.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Feb 24, 2018 0
Community Beginner ,
Feb 28, 2018

Copy link to clipboard

Copied

I further drilled down the issue using log file. I came to know that the app crashes before executing the multiple file select event handler function. I mean below code is executed and multiple file select browse window is opened.

public function ImportImages(event:*):void

{

     var file:File = File.userDirectory;

     file.browseForOpenMultiple("Select Images",[MgrYSIPath.imageFlter]);

     file.addEventListener(FileListEvent.SELECT_MULTIPLE,saveImportImage);

     file.addEventListener(Event.CANCEL, cancelExport);

}

When I select more than 700 high resolution images(more than 5 MB each), the app crashes before event handler function gets executed. Below is the event handler function.

private function saveImportImage(event:FileListEvent):void

{

     setRank();

     SaveImageFiles(event.files);

}

I think selecting more than 700 high resolution images is causing the memory problem. Is there any alternative approach to browseForOpenMultiple?

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Feb 28, 2018 0