Strange goings on

I’ve just finished my app for kids which incorporates flashcards, letters and numbers.
I’m using a sliderGroup to hold all the individual slides. Everything works fine in the simulator and on the iPhone (iOS 5), but the alphabet flashcard slides won’t work on the iPad (iOS 4.3.5) It crashes when loading the scene. The strange thing is, having tested loads of combinations, it will work with only 24 of the 26 slides. It doesn’t matter which two I take out, as long as there’s a maximum of 24 slides.
Is there any way to increase the amount of slides I can display? Or is this a problem with iOS 4?

Sample of the code: I’ve only put in the first two slides and the associated audio files.

[code]

module(…, package.seeall) --ACTIVATE THIS LINE IF USING DIRECTOR; REMOVE IF NOT

local math_abs = math.abs
local cw, ch, ox, oy = display.contentWidth, display.contentHeight, math_abs(display.screenOriginX), math_abs(display.screenOriginY)
–“ox” and “oy” calculate the X/Y ‘offset’ at different screen proportions, i.e. iPhone vs. Galaxy Tab vs. iPad


–Setup Display Groups

local localGroup = display.newGroup()
local GUI = display.newGroup()
local sliderGroup = display.newGroup()

local slideDist = cw+ox+ox --total left-to-right distance of a slide
local slideIndex = 0
local touchPos = 0
local lastPos = 0
local touchTime = 0
–A ‘swipe’ is basically just a SHORT (distance) and FAST (time) screen touch. The variable “coreSwipeDist” sets the DISTANCE aspect
–of a swipe. Default in this module is 1/10th the screen width. Adjust if you desire a longer or shorter distance to register as a ‘swipe’
–The variable “coreSwipeTime” is the TIME aspect (in milliseconds) which registers as a swipe. If the user’s touch is longer than this value,
–this module considers that motion a DRAG/HOLD, not a swipe. Adjust this time value to your desire.
–NOTE!!! After you determine the values that feel right to you, I suggest you replace these variables below (in function “screenMotion”)
–with the hard-coded values, so Corona doesn’t need to waste effort on upvalue lookups.
local coreSwipeDist = cw/10
local coreSwipeTime = 300

local slideTrans = 0 --the tween transition variable; when set to 0, transition is not happening.
local maxSlideIndex = 0 --max number of slides, to be automatically set later.
local resist = 1

local function transComplete( event )

transition.cancel( slideTrans ) ; slideTrans = 0
local targetX = (slideIndex*-slideDist) ; if ( sliderGroup.x ~= targetX ) then sliderGroup.x = targetX end

end
– Sounds for flashcards
local function letASound(event)
audio.play( apple1 )
end

local function letBSound(event)
audio.play( ball1)
end


–Transition to next slide

local function slideTween( targetX )

–Overall transition time is 400 milliseconds by default. Adjust if you desire slower or faster slide movement.
local transTime = ( (math_abs(sliderGroup.x-targetX))/slideDist) * 400
if ( slideTrans ~= 0 ) then transition.cancel( slideTrans ) ; slideTrans = 0 end
slideTrans = transition.to( sliderGroup, { x=targetX, time=transTime, transition = easing.outQuad, onComplete=transComplete } )
end

local function gotoSlide( targetSlide, method )

if ( slideTrans ~= 0 ) then transition.cancel( slideTrans ) ; slideTrans = 0 end
local si = targetSlide-1 ; slideIndex = si ; local destX = (si*-slideDist)
if ( method == “snap” ) then sliderGroup.x = destX ; updateDots( si )
else slideTween( destX )
end
end


–Core touch sensor + movement/swipe function

local function screenMotion( event )

local phase = event.phase ; local eventX = event.x

if ( “began” == phase ) then
if ( slideTrans ~= 0 ) then transition.cancel( slideTrans ) ; slideTrans = 0 end
touchPos = eventX ; lastPos = eventX ; touchTime = event.time

elseif ( “moved” == phase ) then
local dist = eventX-lastPos ; local res = resist
–“resist” is the ratio (percentage) for the end-of-stack spring resistance effect. At either end of your stack of slides, if the
–user tries to slide further, this module “resists” that movement to indicate that there are no more slides, just like iOS! :slight_smile:
–Default is “0.3” on line 126 ; you may change this, but 0.5 or higher risks the ability to move the slide off the screen!
if ( ( slideIndex == 0 and dist > 0 ) or ( slideIndex == maxSlideIndex and dist < 0 ) ) then res = 0.3 else res = 1 end
sliderGroup.x = sliderGroup.x+(dist*res) ; lastPos = eventX ; resist = res

else
local motionTime = system.getTimer()-touchTime
local dist = eventX-touchPos ; local swipeDist = math_abs( dist )
local overallDist = math_abs( sliderGroup.x+(slideIndex*slideDist) )
local goNextSlide = false

if ( resist ~= 1 ) then goNextSlide = false
elseif ( motionTime <= coreSwipeTime and swipeDist >= coreSwipeDist ) then goNextSlide = true
elseif ( motionTime > coreSwipeTime and overallDist >= slideDist*0.5 ) then goNextSlide = true end

if ( goNextSlide == true and dist < 0 and resist == 1 ) then slideIndex = slideIndex+1
elseif ( goNextSlide == true and dist > 0 and resist == 1 ) then slideIndex = slideIndex-1 end
slideTween( slideIndex*-slideDist )
end
end

local function initSetup()

local letAGroup

–create 4 sample slides using a loop:

letAGroup = display.newGroup() --IMPORTANT!!! Create a new display group for each slide!
localGroup:insert(letAGroup) --ACTIVATE THIS LINE IF USING DIRECTOR

– slide background (image or just a simple rect in this example)
local flashA = display.newImageRect( “images/Flashcards/apple.jpg”, 320,480)
flashA:setReferencePoint(display.centerReferencePoint)
flashA.x=cw/2; flashA.y=ch/2
letAGroup:insert( flashA )

sliderGroup:insert( letAGroup )
letAGroup.x = ((sliderGroup.numChildren-1)*slideDist)

local letBGroup

–create 4 sample slides using a loop:

letBGroup = display.newGroup() --IMPORTANT!!! Create a new display group for each slide!
localGroup:insert(letBGroup) --ACTIVATE THIS LINE IF USING DIRECTOR

– slide background (image or just a simple rect in this example)
local flashB = display.newImageRect( “images/Flashcards/ball.jpg”, 320,480)
flashB:setReferencePoint(display.centerReferencePoint)
flashB.x=cw/2; flashB.y=ch/2
letBGroup:insert( flashB )

sliderGroup:insert( letBGroup )
letBGroup.x = ((sliderGroup.numChildren-1)*slideDist)

maxSlideIndex = sliderGroup.numChildren-1
sliderGroup:addEventListener( “touch”, screenMotion )

letAGroup:addEventListener( “tap”, letASound )
letBGroup:addEventListener( “tap”, letBSound )

end

initSetup()

function new()
return localGroup
end
[/code] [import]uid: 92074 topic_id: 17362 reply_id: 317362[/import]

Have you checked for memory leaks?

If you keep your iPad hooked up you can see the log in Xcode and perhaps get an idea of why the crash is occurring as well.

Peach :slight_smile: [import]uid: 52491 topic_id: 17362 reply_id: 65735[/import]

Hmmm, speculating here…

  1. You said 24 slide, no matter which two you remove. This could be causing a memory leak thereby causing your app to crash/terminate.

cheers,

?:slight_smile: [import]uid: 3826 topic_id: 17362 reply_id: 65752[/import]

HI Peach and JayantV,

I had a look in XCode organiser with the iPad connected and got this printed:

Nov 6 10:24:05 unknown kernel[0] : launchd[79] Builtin profile: container (sandbox)
Nov 6 10:24:05 unknown kernel[0] : launchd[79] Container: /private/var/mobile/Applications/2ACD220E-C591-43D2-A0CD-B24E004415AF [69] (sandbox)
Nov 6 10:24:16 unknown SpringBoard[29] : Received memory warning. Level=1
Nov 6 10:24:16 unknown MobileMail[78] : Received memory warning. Level=1
Nov 6 10:24:16 unknown configd[25] : jetsam: kernel memory event (90), free: 556, active: 3850, inactive: 1989, purgeable: 0, wired: 44856
Nov 6 10:24:17 unknown configd[25] : jetsam: kernel memory event (95), free: 429, active: 1789, inactive: 942, purgeable: 0, wired: 51250
Nov 6 10:24:17 unknown configd[25] : jetsam: kernel termination snapshot being created
Nov 6 10:24:17 unknown com.apple.launchd[1] : (com.apple.accessoryd) Exited: Killed: 9
Nov 6 10:24:17 unknown com.apple.launchd[1] : (UIKitApplication:com.apple.mobilemail[0x6237]) Exited: Killed: 9
Nov 6 10:24:17 unknown com.apple.launchd[1] : (com.apple.locationd) Exited: Killed: 9
Nov 6 10:24:17 unknown com.apple.launchd[1] : (UIKitApplication:Learnearly[0xa273]) Exited: Killed: 9
Nov 6 10:24:17 unknown SpringBoard[29] : Received memory warning. Level=2
Nov 6 10:24:17 unknown SpringBoard[29] : Received memory warning. Level=2
Nov 6 10:24:17 unknown SpringBoard[29] : Application ‘Learnearly’ exited abnormally with signal 9: Killed: 9
Nov 6 10:24:17 unknown SpringBoard[29] : Application ‘Mail’ exited abnormally with signal 9: Killed: 9
Nov 6 10:24:17 unknown SpringBoard[29] : Memory level is not normal (71%). Delaying auto-relaunch of ‘Mail’ for 30 seconds.
Nov 6 10:24:18 unknown kernel[0] : launchd[80] Builtin profile: accessoryd (sandbox)
Nov 6 10:24:18 unknown SpringBoard[29] : Received memory warning. Level=2
Nov 6 10:24:18 unknown ReportCrash[82] : libMobileGestalt loadBasebandMobileEquipmentInfo: CommCenter error: 1:45
Nov 6 10:24:18 unknown ReportCrash[82] : libMobileGestalt copyInternationalMobileEquipmentIdentity: Could not get mobile equipment info dictionary
Nov 6 10:24:19 unknown ReportCrash[82] : Saved crashreport to /Library/Logs/CrashReporter/LowMemory-2011-11-06-102419.plist using uid: 0 gid: 0, synthetic_euid: 0 egid: 0
Nov 6 10:24:19 unknown com.apple.locationd[81] : locationd was started after an unclean shutdown
Nov 6 10:24:48 unknown kernel[0] : launchd[83] Builtin profile: MobileMail (sandbox)

I really don’t know what this means. I can see that my application, “Learnearly”, had memory warnings but I don’t know how to fix this. [import]uid: 92074 topic_id: 17362 reply_id: 65756[/import]

You need to work out where the memory leak is happening. You can use this code which will print to the terminal constantly (or modify it so it’s less often, or what have you);

[lua]local function monitorMem(event)
collectgarbage(“collect”)

print( “\nMemUsage: " … (collectgarbage(“count”)/1000) … " MB”)
print("Texture Usage " … system.getInfo( “textureMemoryUsed” ) / 1000000)

return true
end

Runtime:addEventListener(“enterFrame”, monitorMem)[/lua]

Now, the terminal will show memory use. Is it constantly going up? Does it ever go down?

It seems as though you are not cleaning up your assets properly.

This may sound like an odd question, but are you actually removing your images?

I haven’t seen a memory warning on an iPad for a game like this ever and it makes me think that you may have a huge number of images, listeners, etc. that are just sitting there regardless of whether or not they’re being used.

Could this be the case? [import]uid: 52491 topic_id: 17362 reply_id: 65764[/import]

Hi Peach,
yeah I think that could be the case. I’m still not really sure how to remove the images and listeners.
On loadup of the menu screen, the app crashes whilst the flashcards.lua is opening. The menu contains one background image with 6 rectangles for buttons. Should it crash so early in the app?

The memory use in the terminal goes up when I change scenes, and then back down again when I return to the main menu.

I have about 90 images (480x320 jpgs) split over 6 scenes. And a total of 155 mp3s. Each slide in each scene is tappable ( one of the scenes has tappable 3 areas per slide), so I suppose that’s a lot of listeners. Any way of reducing this or making it more efficient?

Thanks [import]uid: 92074 topic_id: 17362 reply_id: 65769[/import]

What kind of memory numbers are you getting?

Is it an iPad or iPad2?
Is it an iPhone 3G, iPhone 4 or iPhone 4s?

Do you have all 155 sounds loaded at once? Are they stereo? 44Khz, 11Khz? How long are the clips?

44Khz stereo sounds will eat up memory in a hurry. For my game I ended up making everything 11kzh mono sounds. I trimmed an excess off the ends to get them as small as I could.

The iPad and iPhone 3GS are 256M memory devices. The iPad2, iPhone4+ are at least 512M devices. And while you might not be leaking memory, if you’re got 155 sounds all loaded up, you’re eating up a ton of memory.
[import]uid: 19626 topic_id: 17362 reply_id: 65780[/import]

Hey robmiracle,

I’m testing on an iPad1 and iPhone 4. I’ve converted all my sounds to 16hz, mono. They’re nearly all just single words, with an average file size of 4kb, with a few of 16kb. Not all loaded at once. I have 26 mp3s loading for the flashcards.lua file. Still no joy. [import]uid: 92074 topic_id: 17362 reply_id: 65848[/import]

Well the iPad1 has half the memory of the iPhone4, so that could explain the different behavior.

Do you need all the sounds loaded all the time?
[import]uid: 19626 topic_id: 17362 reply_id: 65857[/import]