Page 1 of 1

Repeated use of Crop Image causes crash to desktop

Posted: Fri Jul 10, 2015 3:00 pm
by KimD
Windows 7 & Livecode 7.0.6

I'm working on a project which takes a large image (7mb jpg), and chops it up into 9 smaller images.

To replicate the problem that I am experiencing I created a stack with one card. One the one card is the 7mb image, named "OrigImage". Also on the card is a button containing the following code -

Local muImageRef, gsNewImageName, gsDataImg

on mouseUp
Repeat with muImageRef = 1 to 9
Copy image "OrigImage" to this card
Set the name of the last image to "ImageCopy"
Crop image "ImageCopy" to 1000, 1000, 2500, 2500
Put "ImageV" & muImageRef & ".jpg" into gsNewImageName
put the text of image "ImageCopy" into gsDataImg
put gsDataImg into url("binfile:" & gsNewImageName)
Delete image "ImageCopy"
end Repeat
end mouseUp

When I click on the button, livecode carries out between 1 and 3 iterations of the repeat loop (it varies each time) then crashes to desktop with no error message.

If I comment out the crop command - then Livecode finishes all 9 iterations.

I've tried running this with Windows Task Manager on. Livecode fills up progressively more and more memory, and crashes after it has consumed about 1Gb.

Is this known, and is there a work around? I suspect that what I'm looking for is a way to get Livecode to release whatever memory it has used on a Crop operation, before starting the next Crop operation.

Thanks in advance

Re: Repeated use of Crop Image causes crash to desktop

Posted: Fri Jul 10, 2015 3:14 pm
by Klaus
Hi Kim,

looks like CROP is a bit buggy! :shock:

Anyway, here is a workaround WITHOUT copying and cropping your image a couple of times!
Just export a snapshot of the desired image area to file on disk:

Code: Select all

on mouseUp
   repeat with muImageRef = 1 to 9

      ## In a standalone you may not write to every folder, so use a place where your app will definitively have WRITE permission
      ## like "Desktop" or "Documents". Check SPECIALFOLDERPATH in the dictionary!
      ## Put "ImageV" & muImageRef & ".jpg" into gsNewImageName
      put specialfolderpath("desktop") & "/ImageV" & muImageRef & ".jpg" into gsNewImageName
      export snapshot from rect "1000,1000,2500,2500" of img "OrigImage" to file gsNewImageName as JPEG
   end Repeat
end mouseUp
Make sure that the TOPLEFT of your OrigImage is set to 0,0 to get the correct image area,
or whatever part of your image you need to save to file.


Best

Klaus

Re: Repeated use of Crop Image causes crash to desktop

Posted: Fri Jul 10, 2015 3:42 pm
by KimD
Thanks Klaus! Your code runs perfectly on my "replicate the problem" stack. Tomorrow I'll try implementing it in my actual project stack. Thanks again.

Re: Repeated use of Crop Image causes crash to desktop

Posted: Sat Jul 11, 2015 7:16 am
by KimD
Hi Klaus

Based on your suggestion I replaced "Crop" with "Export Snapshot" in my project, and it worked perfectly. Where Crop crashed after 1 to 3 repetitions, Export Snapshot carried out 77 repetitions with no problems, and it was much faster than Crop. The only downside that I can think of to using Export Snapshot is that it doesn't provide the option of keeping the resulting images inside the stack; but I don't need to do that on this occasion so that's OK.

Looks like Crop would benefit from some TLC. Is there a place where I should log this?

Thanks again.

Re: Repeated use of Crop Image causes crash to desktop

Posted: Sat Jul 11, 2015 12:17 pm
by Klaus
Hi Kim,

please check "import snapshot" in the dictionary!
As the name implies it does almost the same as "export snapshot" but can keep the copy in the stack!

Please consider to report the CROPping inconvenience here: http://quality.runrev.com


Best

Klaus

Re: Repeated use of Crop Image causes crash to desktop

Posted: Sun Jul 12, 2015 8:06 am
by KimD
Thanks for the suggestion. I've logged the issue with Crop Image. Regards

Re: Repeated use of Crop Image causes crash to desktop

Posted: Sun Jul 12, 2015 3:16 pm
by FourthWorld
KimD wrote:Thanks for the suggestion. I've logged the issue with Crop Image.
What's the bug report number?