Error while running app on mac simulator, but not on windows

Hi, I had just finished coding some app on my windows desktop, but when I moved it to my mac trying to build it for my iPhone, the simulator crashes after the app splash screen, with this ‘unknown error’, any idea why?
btw, same build on both; mac & windows (2015.2625)
(code is shown within the pic)
#edit: don’t mind the “or 1” in line 207 (app error is without that “or 1”, didn’t save after edit), I tried it to see whether the problem is arithmetical, but after that, got same error but on line 212 or 210, not sure
808oZSl.png

bump

It’s really helpful to copy/paste code when asking questions in the forums (Use the <> button in the forum formatting bar).  As I try to help you I have to keep blowing up your code to see the variables you used.

The error you are getting is rather clear, you’re trying to access something that is nil in line 207.  Since “i” is likely not going to be nil, then either:  photoThumbnals[i] is nil, photoThumbnails[i].width is nil or photoThumbnails[i].height is nil.

There is likely some additional error messages in the console/terminal window that we open with the simulator. You can also add in some print statements to print the values of those three items and see which one is nil and from there you can figure out why they are nil.  There isn’t enough code to provide you any more information on this.  This is all basic debugging.  If you need more help on debugging your project from general terms, please read: http://docs.coronalabs.com/guide/basics/debugging/index.html

Rob

Hi Rob, did you notice that I mentioned it ran on my windows pc, but not on my mac?

Yes, I noticed that, but I still need you to check the things I asked.

Rob

Hi @Rob Miracle, I’m getting the same error while testing on my android device (Built on windows pc)
I give up, here’s the code:

 

-- Project: Business Sample App -- -- File name: photogallery.lua -- -- Author: Corona Labs -- -- Abstract: Display a gallery of photo thumbnails. -- -- -- Target devices: simulator, device -- -- Sample code is MIT licensed, see http://www.coronalabs.com/links/code/license -- Copyright (C) 2013 Corona Labs Inc. All Rights Reserved. --------------------------------------------------------------------------------------- --[[Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.]]--modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, --------------------------------------------------------------------------------------- local composer = require( "composer" ) local scene = composer.newScene() local widget = require("widget") local widget2 = require("widget-extras") local myApp = require("myapp") local \_W = display.contentCenterX local \_H = display.contentCenterY local pPath = "photos/" local ads = require("ads") local \_W = display.contentWidth local \_H = display.contentHeight ads.show( "banner", { x=0, y=\_H-50, appId="xxxx" } ) --widget.setTheme(myApp.theme) --local slideView = require( "slideView" ) -- ScrollView listener local function scrollListener( event ) local phase = event.phase if ( phase == "began" ) then print( "Scroll view was touched" ) elseif ( phase == "moved" ) then print( "Scroll view was moved" ) elseif ( phase == "ended" ) then print( "Scroll view was released" ) end -- In the event a scroll limit is reached... if ( event.limitReached ) then if ( event.direction == "up" ) then print( "Reached top limit" ) elseif ( event.direction == "down" ) then print( "Reached bottom limit" ) elseif ( event.direction == "left" ) then print( "Reached left limit" ) elseif ( event.direction == "right" ) then print( "Reached right limit" ) end end return true end -- Create the widget local scrollView = widget.newScrollView { top = -11, left = 0, width = display.contentWidth, height = display.contentHeight, bottomPadding = 120, id = "onBottom", horizontalScrollDisabled = true, verticalScrollDisabled = false } --[[local topBar = display.newRect(\_W, 0, display.contentWidth, 140) topBar:setFillColor(106/255,106/255,106/255) local topBarText = display.newImage("images/text.png", \_W, 40) topBarText:scale(0.4, 0.4) -- Create a image and insert it into the scroll view --]] local photoFiles = {} for i = 1, 229 do photoFiles[i] = pPath .. i .. ".jpg" end local photosThumbnails = {} local photosThumbGroups = {} local function showPhoto(event) if event.phase == "moved" then local dy = math.abs( ( event.y - event.yStart ) ) if ( dy \> 10 ) then scrollView:takeFocus( event ) end elseif event.phase == "ended" then print("GOT IN HERE") composer.showOverlay("slideView", {time=250, isModal = true, effect="crossFade", params={start=event.target.index, images=photoFiles}}) end return true end local function onAboutClick(event) local t = event.target local aboutGroup = display.newGroup() if event.phase == "began" then t.alpha = 0.5 elseif event.phase == "ended" then t.alpha = 1 --Check bounds. If we are in it then click! local b = t.contentBounds if event.x \>= b.xMin and event.x \<= b.xMax and event.y \>= b.yMin and event.y \<= b.yMax then composer.showOverlay("aboutScreen", {time=250, isModal = true, effect="slideUp"}) end end return true end function scene:create( event ) local sceneGroup = self.view local background = display.newRect(0,0,display.contentWidth, display.contentHeight) background:setFillColor( 0.95, 0.95, 0.95 ) background.x = display.contentWidth / 2 background.y = display.contentHeight / 2 sceneGroup:insert(background) local aboutBtn = display.newImage("images/about.png") aboutBtn:scale(0.15, 0.15) aboutBtn.x = \_W/2+140 aboutBtn.y = \_H/2-250 local row = 0 local col = 0 local thumbnailMask = graphics.newMask("images/mask-80x80.png") local groupOffset = 0 if tonumber( system.getInfo("build") ) \< 2013.2000 then groupOffset = 40 end local function showPhoto(event) if event.phase == "moved" then local dy = math.abs( ( event.y - event.yStart ) ) if ( dy \> 10 ) then scrollView:takeFocus( event ) end elseif event.phase == "ended" then composer.showOverlay("slideView", {time=250, isModal = true, effect="crossFade", params={start=event.target.index, images=photoFiles}}) end return true end aboutBtn:addEventListener("touch", onAboutClick) for i = 1, #photoFiles do photosThumbnails[i] = display.newImage(photoFiles[i]) local aspectRatio = photosThumbnails[i].width / photosThumbnails[i].height local scale if aspectRatio \> 1 then -- landscape photo scale = 80 / photosThumbnails[i].height else scale = 80 / photosThumbnails[i].width end --print(scale, aspectRatio, photosThumbnails[i].width, photosThumbnails[i].width \* scale, photosThumbnails[i].height, photosThumbnails[i].height \* scale) photosThumbnails[i]:scale(scale,scale) photosThumbGroups[i] = display.newGroup() photosThumbnails[i].x = groupOffset --col \* 80 + 40 photosThumbnails[i].y = groupOffset --row \* 80 + 40 + 70 photosThumbGroups[i]:insert(photosThumbnails[i]) photosThumbGroups[i].x = col \* 80 + 40 photosThumbGroups[i].y = row \* 80 + 40 + 70 photosThumbGroups[i]:setMask(thumbnailMask) photosThumbGroups[i].maskX = groupOffset photosThumbGroups[i].maskY = groupOffset photosThumbGroups[i].index = i photosThumbGroups[i]:addEventListener("touch", showPhoto) scrollView:insert(photosThumbGroups[i]) col = col + 1 if col \> 3 then row = row + 1 col = 0 end sceneGroup:insert(scrollView) end print("Memory", system.getInfo("textureMemoryUsed") / (1024 \* 1024)) local navBar = widget.newNavigationBar({ title = "HD Wallpapers", top = -8, backgroundColor = { 0.44, 0.44, 0.44, 0.95 }, titleColor = {1, 1, 1}, font = "HelveticaNeue" }) sceneGroup:insert(navBar) sceneGroup:insert(aboutBtn) end function scene:show( event ) local sceneGroup = self.view end function scene:hide( event ) local sceneGroup = self.view -- -- Clean up any native objects and Runtime listeners, timers, etc. -- end function scene:destroy( event ) local sceneGroup = self.view end --------------------------------------------------------------------------------- -- END OF YOUR IMPLEMENTATION --------------------------------------------------------------------------------- scene:addEventListener( "create", scene ) scene:addEventListener( "show", scene ) scene:addEventListener( "hide", scene ) scene:addEventListener( "destroy", scene ) --------------------------------------------------------------------------------- return scene

it’s from the Business Sample App

I did a temporary fix for that, by just loading 100 pictures out of 229 and scaling them without checking their aspect ratio:

 for i = 1, 100 do photosThumbnails[i] = display.newImage(photoFiles[i]) --print(scale, aspectRatio, photosThumbnails[i].width, photosThumbnails[i].width \* scale, photosThumbnails[i].height, photosThumbnails[i].height \* scale) photosThumbnails[i]:scale(77/photosThumbnails[i].width,77/photosThumbnails[i].height)

Looks like it’s a picture that is causing this issue? How is that?

Also, when clicking a picture (Android device) I get another error…

 

Runtime Error: C:\etc\etc\etc\etc\slideView.lua:119: attempt to index local 'p' (a nil value)

slideView:
 

-- slideView.lua -- -- Version 1.0 -- -- Copyright (C) 2010 Corona Labs Inc. All Rights Reserved. -- -- Permission is hereby granted, free of charge, to any person obtaining a copy of -- this software and associated documentation files (the "Software"), to deal in the -- Software without restriction, including without limitation the rights to use, copy, -- modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, -- and to permit persons to whom the Software is furnished to do so, subject to the -- following conditions: -- -- The above copyright notice and this permission notice shall be included in all copies -- or substantial portions of the Software. -- -- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, -- INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR -- PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE -- FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -- OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -- DEALINGS IN THE SOFTWARE. local sharingWidget = require ("widget-extras") local composer = require( "composer" ) local scene = composer.newScene() local widget = require("widget") local myApp = require( "myapp" ) widget.setTheme(myApp.theme) local screenW, screenH = display.contentWidth, display.contentHeight local viewableScreenW, viewableScreenH = display.viewableContentWidth, display.viewableContentHeight local screenOffsetW, screenOffsetH = display.contentWidth - display.viewableContentWidth, display.contentHeight - display.viewableContentHeight local imgNum = nil local images = nil local touchListener, nextImage, prevImage, cancelMove, initImage, jumpToImage local background local imageNumberText, imageNumberTextShadow local backbutton local function goBack( event ) print(event.phase) if event.phase == "ended" then composer.hideOverlay( "fade", 250 ) end return true end --function new( imageSet, slideBackground, top, bottom ) function scene:create( event ) local sceneGroup = self.view local pad = 0 local top = top or 0 local bottom = bottom or 0 local start = 1 if event.params and event.params.start then start = event.params.start end local imageSet = event.params.images assert(imageSet, "Error: image list not set") viewableScreenW = display.contentWidth viewableScreenH = display.contentHeight - 120 -- status bar + top bar + tabBar local background = display.newRect(0,0,display.contentWidth, display.contentHeight) background:setFillColor( 0.95, 0.95, 0.95 ) background.x = display.contentWidth / 2 background.y = display.contentHeight / 2 sceneGroup:insert(background) sharingPanel = widget.newSharingPanel({ }) local function showPanel( event ) if event.phase == "ended" then sharingPanel:show() end return true end local leftButton = { onEvent = goBack, width = 59, height = 32, defaultFile = "images/backbutton7\_white.png", overFile = "images/backbutton7\_white.png" } local rightButton = { onEvent = showPanel, width = 40, height = 48, defaultFile = "images/sendToButton.png", overFile = "images/sendToButtonOver.png", } local navBar = widget.newNavigationBar({ title = "Photo Gallery", backgroundColor = { 0.44, 0.44, 0.44 }, titleColor = {1, 1, 1}, font = "HelveticaNeue", leftButton = leftButton, rightButton = rightButton }) sceneGroup:insert(navBar) images = {} for i = 1,#imageSet do local p = display.newImage(imageSet[i]) local h = viewableScreenH-(top+bottom) if p.width \> viewableScreenW or p.height \> h then if p.width/viewableScreenW \> p.height/h then p.xScale = viewableScreenW/p.width p.yScale = viewableScreenW/p.width -- asd else p.xScale = h/p.height p.yScale = h/p.height end end sceneGroup:insert(p) if (i \> 1) then p.x = screenW\*1.5 + pad -- all images offscreen except the first one else p.x = screenW\*.5 end p.y = h\*.5 + 20 + 50 images[i] = p end local defaultString = "1 of " .. #images imgNum = 1 sceneGroup.x = 0 sceneGroup.y = top + display.screenOriginY function touchListener (self, touch) local phase = touch.phase print("slides", phase) if ( phase == "began" ) then -- Subsequent touch events will target button even if they are outside the contentBounds of button display.getCurrentStage():setFocus( self ) self.isFocus = true startPos = touch.x prevPos = touch.x elseif( self.isFocus ) then if ( phase == "moved" ) then if tween then transition.cancel(tween) end print(imgNum) local delta = touch.x - prevPos prevPos = touch.x images[imgNum].x = images[imgNum].x + delta if (images[imgNum-1]) then images[imgNum-1].x = images[imgNum-1].x + delta end if (images[imgNum+1]) then images[imgNum+1].x = images[imgNum+1].x + delta end elseif ( phase == "ended" or phase == "cancelled" ) then dragDistance = touch.x - startPos print("dragDistance: " .. dragDistance) if (dragDistance \< -40 and imgNum \< #images) then nextImage() elseif (dragDistance \> 40 and imgNum \> 1) then prevImage() else cancelMove() end if ( phase == "cancelled" ) then cancelMove() end -- Allow touch events to be sent normally to the objects they "hit" display.getCurrentStage():setFocus( nil ) self.isFocus = false end end return true end function setSlideNumber() print("setSlideNumber", imgNum .. " of " .. #images) navBar:setLabel( imgNum .. " of " .. #images ) myApp.chosenImage = imgNum end function cancelTween() if prevTween then transition.cancel(prevTween) end prevTween = tween end function nextImage() tween = transition.to( images[imgNum], {time=400, x=(screenW\*.5 + pad)\*-1, transition=easing.outExpo } ) tween = transition.to( images[imgNum+1], {time=400, x=screenW\*.5, transition=easing.outExpo } ) imgNum = imgNum + 1 initImage(imgNum) end function prevImage() tween = transition.to( images[imgNum], {time=400, x=screenW\*1.5+pad, transition=easing.outExpo } ) tween = transition.to( images[imgNum-1], {time=400, x=screenW\*.5, transition=easing.outExpo } ) imgNum = imgNum - 1 initImage(imgNum) end function cancelMove() tween = transition.to( images[imgNum], {time=400, x=screenW\*.5, transition=easing.outExpo } ) tween = transition.to( images[imgNum-1], {time=400, x=(screenW\*.5 + pad)\*-1, transition=easing.outExpo } ) tween = transition.to( images[imgNum+1], {time=400, x=screenW\*1.5+pad, transition=easing.outExpo } ) end function initImage(num) if (num \< #images) then images[num+1].x = screenW\*1.5 + pad end if (num \> 1) then images[num-1].x = (screenW\*.5 + pad)\*-1 end setSlideNumber() end background.touch = touchListener background:addEventListener( "touch", background ) ------------------------ -- Define public methods function jumpToImage(num) local i print("jumpToImage") print("#images", #images) for i = 1, #images do if i \< num then images[i].x = -screenW\*.5; elseif i \> num then images[i].x = screenW\*1.5 + pad else images[i].x = screenW\*.5 - pad end end imgNum = num initImage(imgNum) end jumpToImage(start) end function scene:show( event ) local sceneGroup = self.view end function scene:hide( event ) local sceneGroup = self.view -- -- Clean up any native objects and Runtime listeners, timers, etc. -- end function scene:destroy( event ) local sceneGroup = self.view end --------------------------------------------------------------------------------- -- END OF YOUR IMPLEMENTATION --------------------------------------------------------------------------------- scene:addEventListener( "create", scene ) scene:addEventListener( "show", scene ) scene:addEventListener( "hide", scene ) scene:addEventListener( "destroy", scene ) --------------------------------------------------------------------------------- return scene

Dumping your entire code block in here isn’t helpful.

If you have an image crashing your app, perhaps that image is corrupt or not in a valid format. There are several things that can cause a corrupt image. It could be as simple as naming an image .png when it’s really a .jpg. Some software packages use the filename others look at the metadata in the file to determine it’s type.

Next, when you have a particular line number, post the code around that. Its good to know its the Business Sample App, but if you’ve made changes, then we might need to see what we changed.  What line 119 of slideview.lua?

Nevermind, it took the CSS a little while to load and I can see the line numbers now.  Try changing:

if p.width > viewableScreenW or p.height > h then

to

if p and ( p.width > viewableScreenW or p.height > h ) then

Rob

I did not make any changes to both files, just added extra stuff
also, all of the pictures are of type jpg
4o1aImI.png

else they wouldn’t load in the first place

--photogallery.lua local photoFiles = {} for i = 1, 229 do photoFiles[i] = pPath .. i .. ".jpg" end

I did this and got another error:

 

Runtime Error C:\..\..\..\..\slideView.lua:128: ERROR: table expected. If this is a function call, you might have used '.' instead of ':'

--slideView.lua sceneGroup:insert(p)

this is quite annoying, let’s not dig deep into this, so what could be the problem? I doubt the pictures, however, it says that they’re all jpg type, and I also checked them one by one… What should I do?

 

If it can’t load the image for some reason, p will be nil.  You can’t insert nil into a group.  You need to test that you actually successfully created the display object before you use it.  That’s what the “if p” did in the previous suggestion.  You might want to print out the file name of the file that’s failing and take a look at it.

Corona SDK uses whatever native library exists for opening and decoding an image and perhaps there is some minor difference between how Windows handles a potentially corrupt image and how the Mac handles it.  It could be something like corrupt metadata or CMYK JPEG (Instead of the expected RGB).

Rob

bump

It’s really helpful to copy/paste code when asking questions in the forums (Use the <> button in the forum formatting bar).  As I try to help you I have to keep blowing up your code to see the variables you used.

The error you are getting is rather clear, you’re trying to access something that is nil in line 207.  Since “i” is likely not going to be nil, then either:  photoThumbnals[i] is nil, photoThumbnails[i].width is nil or photoThumbnails[i].height is nil.

There is likely some additional error messages in the console/terminal window that we open with the simulator. You can also add in some print statements to print the values of those three items and see which one is nil and from there you can figure out why they are nil.  There isn’t enough code to provide you any more information on this.  This is all basic debugging.  If you need more help on debugging your project from general terms, please read: http://docs.coronalabs.com/guide/basics/debugging/index.html

Rob

Hi Rob, did you notice that I mentioned it ran on my windows pc, but not on my mac?

Yes, I noticed that, but I still need you to check the things I asked.

Rob

Hi @Rob Miracle, I’m getting the same error while testing on my android device (Built on windows pc)
I give up, here’s the code:

 

-- Project: Business Sample App -- -- File name: photogallery.lua -- -- Author: Corona Labs -- -- Abstract: Display a gallery of photo thumbnails. -- -- -- Target devices: simulator, device -- -- Sample code is MIT licensed, see http://www.coronalabs.com/links/code/license -- Copyright (C) 2013 Corona Labs Inc. All Rights Reserved. --------------------------------------------------------------------------------------- --[[Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.]]--modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, --------------------------------------------------------------------------------------- local composer = require( "composer" ) local scene = composer.newScene() local widget = require("widget") local widget2 = require("widget-extras") local myApp = require("myapp") local \_W = display.contentCenterX local \_H = display.contentCenterY local pPath = "photos/" local ads = require("ads") local \_W = display.contentWidth local \_H = display.contentHeight ads.show( "banner", { x=0, y=\_H-50, appId="xxxx" } ) --widget.setTheme(myApp.theme) --local slideView = require( "slideView" ) -- ScrollView listener local function scrollListener( event ) local phase = event.phase if ( phase == "began" ) then print( "Scroll view was touched" ) elseif ( phase == "moved" ) then print( "Scroll view was moved" ) elseif ( phase == "ended" ) then print( "Scroll view was released" ) end -- In the event a scroll limit is reached... if ( event.limitReached ) then if ( event.direction == "up" ) then print( "Reached top limit" ) elseif ( event.direction == "down" ) then print( "Reached bottom limit" ) elseif ( event.direction == "left" ) then print( "Reached left limit" ) elseif ( event.direction == "right" ) then print( "Reached right limit" ) end end return true end -- Create the widget local scrollView = widget.newScrollView { top = -11, left = 0, width = display.contentWidth, height = display.contentHeight, bottomPadding = 120, id = "onBottom", horizontalScrollDisabled = true, verticalScrollDisabled = false } --[[local topBar = display.newRect(\_W, 0, display.contentWidth, 140) topBar:setFillColor(106/255,106/255,106/255) local topBarText = display.newImage("images/text.png", \_W, 40) topBarText:scale(0.4, 0.4) -- Create a image and insert it into the scroll view --]] local photoFiles = {} for i = 1, 229 do photoFiles[i] = pPath .. i .. ".jpg" end local photosThumbnails = {} local photosThumbGroups = {} local function showPhoto(event) if event.phase == "moved" then local dy = math.abs( ( event.y - event.yStart ) ) if ( dy \> 10 ) then scrollView:takeFocus( event ) end elseif event.phase == "ended" then print("GOT IN HERE") composer.showOverlay("slideView", {time=250, isModal = true, effect="crossFade", params={start=event.target.index, images=photoFiles}}) end return true end local function onAboutClick(event) local t = event.target local aboutGroup = display.newGroup() if event.phase == "began" then t.alpha = 0.5 elseif event.phase == "ended" then t.alpha = 1 --Check bounds. If we are in it then click! local b = t.contentBounds if event.x \>= b.xMin and event.x \<= b.xMax and event.y \>= b.yMin and event.y \<= b.yMax then composer.showOverlay("aboutScreen", {time=250, isModal = true, effect="slideUp"}) end end return true end function scene:create( event ) local sceneGroup = self.view local background = display.newRect(0,0,display.contentWidth, display.contentHeight) background:setFillColor( 0.95, 0.95, 0.95 ) background.x = display.contentWidth / 2 background.y = display.contentHeight / 2 sceneGroup:insert(background) local aboutBtn = display.newImage("images/about.png") aboutBtn:scale(0.15, 0.15) aboutBtn.x = \_W/2+140 aboutBtn.y = \_H/2-250 local row = 0 local col = 0 local thumbnailMask = graphics.newMask("images/mask-80x80.png") local groupOffset = 0 if tonumber( system.getInfo("build") ) \< 2013.2000 then groupOffset = 40 end local function showPhoto(event) if event.phase == "moved" then local dy = math.abs( ( event.y - event.yStart ) ) if ( dy \> 10 ) then scrollView:takeFocus( event ) end elseif event.phase == "ended" then composer.showOverlay("slideView", {time=250, isModal = true, effect="crossFade", params={start=event.target.index, images=photoFiles}}) end return true end aboutBtn:addEventListener("touch", onAboutClick) for i = 1, #photoFiles do photosThumbnails[i] = display.newImage(photoFiles[i]) local aspectRatio = photosThumbnails[i].width / photosThumbnails[i].height local scale if aspectRatio \> 1 then -- landscape photo scale = 80 / photosThumbnails[i].height else scale = 80 / photosThumbnails[i].width end --print(scale, aspectRatio, photosThumbnails[i].width, photosThumbnails[i].width \* scale, photosThumbnails[i].height, photosThumbnails[i].height \* scale) photosThumbnails[i]:scale(scale,scale) photosThumbGroups[i] = display.newGroup() photosThumbnails[i].x = groupOffset --col \* 80 + 40 photosThumbnails[i].y = groupOffset --row \* 80 + 40 + 70 photosThumbGroups[i]:insert(photosThumbnails[i]) photosThumbGroups[i].x = col \* 80 + 40 photosThumbGroups[i].y = row \* 80 + 40 + 70 photosThumbGroups[i]:setMask(thumbnailMask) photosThumbGroups[i].maskX = groupOffset photosThumbGroups[i].maskY = groupOffset photosThumbGroups[i].index = i photosThumbGroups[i]:addEventListener("touch", showPhoto) scrollView:insert(photosThumbGroups[i]) col = col + 1 if col \> 3 then row = row + 1 col = 0 end sceneGroup:insert(scrollView) end print("Memory", system.getInfo("textureMemoryUsed") / (1024 \* 1024)) local navBar = widget.newNavigationBar({ title = "HD Wallpapers", top = -8, backgroundColor = { 0.44, 0.44, 0.44, 0.95 }, titleColor = {1, 1, 1}, font = "HelveticaNeue" }) sceneGroup:insert(navBar) sceneGroup:insert(aboutBtn) end function scene:show( event ) local sceneGroup = self.view end function scene:hide( event ) local sceneGroup = self.view -- -- Clean up any native objects and Runtime listeners, timers, etc. -- end function scene:destroy( event ) local sceneGroup = self.view end --------------------------------------------------------------------------------- -- END OF YOUR IMPLEMENTATION --------------------------------------------------------------------------------- scene:addEventListener( "create", scene ) scene:addEventListener( "show", scene ) scene:addEventListener( "hide", scene ) scene:addEventListener( "destroy", scene ) --------------------------------------------------------------------------------- return scene

it’s from the Business Sample App

I did a temporary fix for that, by just loading 100 pictures out of 229 and scaling them without checking their aspect ratio:

 for i = 1, 100 do photosThumbnails[i] = display.newImage(photoFiles[i]) --print(scale, aspectRatio, photosThumbnails[i].width, photosThumbnails[i].width \* scale, photosThumbnails[i].height, photosThumbnails[i].height \* scale) photosThumbnails[i]:scale(77/photosThumbnails[i].width,77/photosThumbnails[i].height)

Looks like it’s a picture that is causing this issue? How is that?

Also, when clicking a picture (Android device) I get another error…

 

Runtime Error: C:\etc\etc\etc\etc\slideView.lua:119: attempt to index local 'p' (a nil value)

slideView:
 

-- slideView.lua -- -- Version 1.0 -- -- Copyright (C) 2010 Corona Labs Inc. All Rights Reserved. -- -- Permission is hereby granted, free of charge, to any person obtaining a copy of -- this software and associated documentation files (the "Software"), to deal in the -- Software without restriction, including without limitation the rights to use, copy, -- modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, -- and to permit persons to whom the Software is furnished to do so, subject to the -- following conditions: -- -- The above copyright notice and this permission notice shall be included in all copies -- or substantial portions of the Software. -- -- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, -- INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR -- PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE -- FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -- OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -- DEALINGS IN THE SOFTWARE. local sharingWidget = require ("widget-extras") local composer = require( "composer" ) local scene = composer.newScene() local widget = require("widget") local myApp = require( "myapp" ) widget.setTheme(myApp.theme) local screenW, screenH = display.contentWidth, display.contentHeight local viewableScreenW, viewableScreenH = display.viewableContentWidth, display.viewableContentHeight local screenOffsetW, screenOffsetH = display.contentWidth - display.viewableContentWidth, display.contentHeight - display.viewableContentHeight local imgNum = nil local images = nil local touchListener, nextImage, prevImage, cancelMove, initImage, jumpToImage local background local imageNumberText, imageNumberTextShadow local backbutton local function goBack( event ) print(event.phase) if event.phase == "ended" then composer.hideOverlay( "fade", 250 ) end return true end --function new( imageSet, slideBackground, top, bottom ) function scene:create( event ) local sceneGroup = self.view local pad = 0 local top = top or 0 local bottom = bottom or 0 local start = 1 if event.params and event.params.start then start = event.params.start end local imageSet = event.params.images assert(imageSet, "Error: image list not set") viewableScreenW = display.contentWidth viewableScreenH = display.contentHeight - 120 -- status bar + top bar + tabBar local background = display.newRect(0,0,display.contentWidth, display.contentHeight) background:setFillColor( 0.95, 0.95, 0.95 ) background.x = display.contentWidth / 2 background.y = display.contentHeight / 2 sceneGroup:insert(background) sharingPanel = widget.newSharingPanel({ }) local function showPanel( event ) if event.phase == "ended" then sharingPanel:show() end return true end local leftButton = { onEvent = goBack, width = 59, height = 32, defaultFile = "images/backbutton7\_white.png", overFile = "images/backbutton7\_white.png" } local rightButton = { onEvent = showPanel, width = 40, height = 48, defaultFile = "images/sendToButton.png", overFile = "images/sendToButtonOver.png", } local navBar = widget.newNavigationBar({ title = "Photo Gallery", backgroundColor = { 0.44, 0.44, 0.44 }, titleColor = {1, 1, 1}, font = "HelveticaNeue", leftButton = leftButton, rightButton = rightButton }) sceneGroup:insert(navBar) images = {} for i = 1,#imageSet do local p = display.newImage(imageSet[i]) local h = viewableScreenH-(top+bottom) if p.width \> viewableScreenW or p.height \> h then if p.width/viewableScreenW \> p.height/h then p.xScale = viewableScreenW/p.width p.yScale = viewableScreenW/p.width -- asd else p.xScale = h/p.height p.yScale = h/p.height end end sceneGroup:insert(p) if (i \> 1) then p.x = screenW\*1.5 + pad -- all images offscreen except the first one else p.x = screenW\*.5 end p.y = h\*.5 + 20 + 50 images[i] = p end local defaultString = "1 of " .. #images imgNum = 1 sceneGroup.x = 0 sceneGroup.y = top + display.screenOriginY function touchListener (self, touch) local phase = touch.phase print("slides", phase) if ( phase == "began" ) then -- Subsequent touch events will target button even if they are outside the contentBounds of button display.getCurrentStage():setFocus( self ) self.isFocus = true startPos = touch.x prevPos = touch.x elseif( self.isFocus ) then if ( phase == "moved" ) then if tween then transition.cancel(tween) end print(imgNum) local delta = touch.x - prevPos prevPos = touch.x images[imgNum].x = images[imgNum].x + delta if (images[imgNum-1]) then images[imgNum-1].x = images[imgNum-1].x + delta end if (images[imgNum+1]) then images[imgNum+1].x = images[imgNum+1].x + delta end elseif ( phase == "ended" or phase == "cancelled" ) then dragDistance = touch.x - startPos print("dragDistance: " .. dragDistance) if (dragDistance \< -40 and imgNum \< #images) then nextImage() elseif (dragDistance \> 40 and imgNum \> 1) then prevImage() else cancelMove() end if ( phase == "cancelled" ) then cancelMove() end -- Allow touch events to be sent normally to the objects they "hit" display.getCurrentStage():setFocus( nil ) self.isFocus = false end end return true end function setSlideNumber() print("setSlideNumber", imgNum .. " of " .. #images) navBar:setLabel( imgNum .. " of " .. #images ) myApp.chosenImage = imgNum end function cancelTween() if prevTween then transition.cancel(prevTween) end prevTween = tween end function nextImage() tween = transition.to( images[imgNum], {time=400, x=(screenW\*.5 + pad)\*-1, transition=easing.outExpo } ) tween = transition.to( images[imgNum+1], {time=400, x=screenW\*.5, transition=easing.outExpo } ) imgNum = imgNum + 1 initImage(imgNum) end function prevImage() tween = transition.to( images[imgNum], {time=400, x=screenW\*1.5+pad, transition=easing.outExpo } ) tween = transition.to( images[imgNum-1], {time=400, x=screenW\*.5, transition=easing.outExpo } ) imgNum = imgNum - 1 initImage(imgNum) end function cancelMove() tween = transition.to( images[imgNum], {time=400, x=screenW\*.5, transition=easing.outExpo } ) tween = transition.to( images[imgNum-1], {time=400, x=(screenW\*.5 + pad)\*-1, transition=easing.outExpo } ) tween = transition.to( images[imgNum+1], {time=400, x=screenW\*1.5+pad, transition=easing.outExpo } ) end function initImage(num) if (num \< #images) then images[num+1].x = screenW\*1.5 + pad end if (num \> 1) then images[num-1].x = (screenW\*.5 + pad)\*-1 end setSlideNumber() end background.touch = touchListener background:addEventListener( "touch", background ) ------------------------ -- Define public methods function jumpToImage(num) local i print("jumpToImage") print("#images", #images) for i = 1, #images do if i \< num then images[i].x = -screenW\*.5; elseif i \> num then images[i].x = screenW\*1.5 + pad else images[i].x = screenW\*.5 - pad end end imgNum = num initImage(imgNum) end jumpToImage(start) end function scene:show( event ) local sceneGroup = self.view end function scene:hide( event ) local sceneGroup = self.view -- -- Clean up any native objects and Runtime listeners, timers, etc. -- end function scene:destroy( event ) local sceneGroup = self.view end --------------------------------------------------------------------------------- -- END OF YOUR IMPLEMENTATION --------------------------------------------------------------------------------- scene:addEventListener( "create", scene ) scene:addEventListener( "show", scene ) scene:addEventListener( "hide", scene ) scene:addEventListener( "destroy", scene ) --------------------------------------------------------------------------------- return scene

Dumping your entire code block in here isn’t helpful.

If you have an image crashing your app, perhaps that image is corrupt or not in a valid format. There are several things that can cause a corrupt image. It could be as simple as naming an image .png when it’s really a .jpg. Some software packages use the filename others look at the metadata in the file to determine it’s type.

Next, when you have a particular line number, post the code around that. Its good to know its the Business Sample App, but if you’ve made changes, then we might need to see what we changed.  What line 119 of slideview.lua?

Nevermind, it took the CSS a little while to load and I can see the line numbers now.  Try changing:

if p.width > viewableScreenW or p.height > h then

to

if p and ( p.width > viewableScreenW or p.height > h ) then

Rob