Repeated use of Crop Image causes crash to desktop

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: Klaus, FourthWorld, heatherlaine, kevinmiller

Post Reply
KimD
Posts: 203
Joined: Wed Jul 08, 2015 5:51 am
Location: Wellington, New Zealand

Repeated use of Crop Image causes crash to desktop

Post by KimD » Fri Jul 10, 2015 3:00 pm

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

Klaus
Posts: 11826
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Repeated use of Crop Image causes crash to desktop

Post by Klaus » Fri Jul 10, 2015 3:14 pm

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

KimD
Posts: 203
Joined: Wed Jul 08, 2015 5:51 am
Location: Wellington, New Zealand

Re: Repeated use of Crop Image causes crash to desktop

Post by KimD » Fri Jul 10, 2015 3:42 pm

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.

KimD
Posts: 203
Joined: Wed Jul 08, 2015 5:51 am
Location: Wellington, New Zealand

Re: Repeated use of Crop Image causes crash to desktop

Post by KimD » Sat Jul 11, 2015 7:16 am

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.

Klaus
Posts: 11826
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Repeated use of Crop Image causes crash to desktop

Post by Klaus » Sat Jul 11, 2015 12:17 pm

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

KimD
Posts: 203
Joined: Wed Jul 08, 2015 5:51 am
Location: Wellington, New Zealand

Re: Repeated use of Crop Image causes crash to desktop

Post by KimD » Sun Jul 12, 2015 8:06 am

Thanks for the suggestion. I've logged the issue with Crop Image. Regards

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7724
Joined: Sat Apr 08, 2006 7:05 am
Location: Los Angeles
Contact:

Re: Repeated use of Crop Image causes crash to desktop

Post by FourthWorld » Sun Jul 12, 2015 3:16 pm

KimD wrote:Thanks for the suggestion. I've logged the issue with Crop Image.
What's the bug report number?
Richard Gaskin
Community volunteer LiveCode Community Liaison

LiveCode development, training, and consulting services: Fourth World Systems: http://FourthWorld.com
LiveCode User Group on Facebook : http://FaceBook.com/groups/LiveCodeUsers/

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”