I have two scenes which work perfectly fine by themselves, even when activated multiple times. However, if I activate one scene and then the other, the program crashes with a "attempt to index field 'contentBounds' (a nil value)" error.
From my research thus far, I've concluded this error is being caused by an internal function call of 'composer.gotoScene' via '_saveSceneAndHide'. ('contentBounds' isn't anywhere in the code itself.)
My current hypothesis is that this is happening because I'm not returning to some prior scene; most of the code is running inside main.lua and I've recently started adding scenes for auxiliary stuff (e.g. a Settings Menu). I didn't know about scenes when I started this project and I've been trying to use the best methods as I move forward.
So, I guess I'm asking: am I required to use scenes differently if I'm going to use them (more than 1, anyway), or is there something else I'm doing wrong / another method?
Here's simplified example code I made to verify the error wasn't from something else. Going to either scene works fine, but it crashes if you go to one scene and then to the other:
local composer = require("composer") ButtonAA = display.newText("AAAAA", 100, 300, native.systemFont, 25); ButtonBB = display.newText("BBBBB", 500, 300, native.systemFont, 25); function ButtonAAListener(event) composer.gotoScene("sceneAA") end function ButtonBBListener(event) composer.gotoScene("sceneBB") end ButtonAA:addEventListener("tap", ButtonAAListener) ButtonBB:addEventListener("tap", ButtonBBListener)
sceneAA / sceneBB.lua:
local composer = require("composer") local scene = composer.newScene() function scene:create(event) local sceneGroup = self.view ButtonAA.alpha = 0 ButtonBB.alpha = 0 local ReturnToMenuText = display.newText("Return AA", 140, 300, native.systemFont, 30); sceneGroup:insert(ReturnToMenuText) ReturnToMenuText:addEventListener("tap", ReturnToMenuListener) end function ReturnToMenuListener(event) composer.removeScene("sceneAA") ButtonAA.alpha = 1 ButtonBB.alpha = 1 end scene:addEventListener("create", scene) return scene
(AA and BB are identical except for changing the text label and the scene to remove.)