Composer.HideOverlay throws nil value error

I made an overlay that I use as a form for people to enter things. I’m also making use of the material ui plugin, there’s a “cancel” button on the overlay that of course removes the over lay when clicked. The problem is, after the first 2 times using the cancel button, it throws this error:

ERROR: Runtime error 14:00:07.798 ?:0: attempt to call method 'setFillColor' (a nil value) 14:00:07.798 stack traceback: 14:00:07.798 ?: in function '?' 14:00:07.798 ?: in function \<?:182\>

The problem now is, this error makes no sense, I can’t figure out where the problem is from and I tried removing every line with “setFillColor” from the overlay and parent scene and it still throws this error on the third try. I don’t know if this is a bug or something, I really don’t know what to do at this point, maybe I’m using hideOverlay wrong, my code is below, this is the code for the overlay:

local composer = require ( "composer" ) local widget = require( "widget" ) local json = require( "json" ) local loadsave = require( "loadsave" ) local Stack = require( "Stack" ) local mui = require( "plugin.materialui" ) local scene = composer.newScene() --Function to hide overlay local function closeThis( event ) print (event.phase) composer.hideOverlay("fade", 100 ) print("add closethis") return true end -- Create the widget function scene:create( event ) local sceneGroup = self.view print("add create") mui.init() local background = display.newRect( display.contentCenterX, display.contentCenterY, display.contentWidth, display.contentHeight ) background:setFillColor( 1 ) -- white local sideMargin = 16 local tbHeight = mui.getScaleVal(46) local origin = 44 + display.topStatusBarContentHeight + (tbHeight/2) mui.newTextField({ name = "Name", labelText = "Name", text = composer.getVariable("username"), font = composer.getVariable("defaultItemFont"), width = display.contentWidth - 32, height = tbHeight, x = 16 + ((display.contentWidth - 32)/2), fontSize = 12, textBoxFontSize = 16, activeColor = { 0, 0, 0, 1 }, inactiveColor = { 0.5, 0.5, 0.5, 1 }, callBack = mui.textfieldCallBack }) mui.getWidgetProperty("Name", "object").y = origin + ((mui.getWidgetProperty("Name", "label").height) \* 2) + 16 mui.newTextField({ name = "Notes", labelText = "Notes", text = "Additional Notes", font = composer.getVariable("defaultItemFont"), width = display.contentWidth - 32, height = tbHeight, x = 16 + ((display.contentWidth - 32)/2), fontSize = 12, textBoxFontSize = 16, activeColor = { 0, 0, 0, 1 }, inactiveColor = { 0.5, 0.5, 0.5, 1 }, callBack = mui.textfieldCallBack }) mui.getWidgetProperty("Notes", "object").y = ((origin + ((mui.getWidgetProperty("Notes", "label").height) \* 2)) \* 2) mui.newTextField({ name = "Contact", labelText = "Contact", text = "Phone Number or Email", font = composer.getVariable("defaultItemFont"), width = display.contentWidth - 32, height = tbHeight, x = 16 + ((display.contentWidth - 32)/2), fontSize = 12, textBoxFontSize = 16, activeColor = { 0, 0, 0, 1 }, inactiveColor = { 0.5, 0.5, 0.5, 1 }, callBack = mui.textfieldCallBack }) mui.getWidgetProperty("Contact", "object").y = ((origin + ((mui.getWidgetProperty("Contact", "label").height) \* 2)) \* 3) - 16 mui.newRoundedRectButton({ name = "addButton", text = "ADD", width = mui.getScaleVal(180), height = 36, radius = 2, textMargin = 16, x = display.contentWidth - 16 - (mui.getScaleVal(180)/2), y = ((origin + ((mui.getWidgetProperty("Contact", "label").height) \* 2)) \* 3.5), font = composer.getVariable("defaultItemFont"), fillColor = { 1, 1, 1, 1}, textColor = composer.getVariable("mainColor"), touchpoint = false, callBack = nil, animation = { animationType = "colorTransition", -- the only animation type at this time. transitionStartColor = {0.88,0.88,0.88,1}, -- RGB(A) color in percent transitionEndColor = { 1, 1, 1, 1 }, -- RGB(A) color in percent transition = easing.inOutExpo, -- transition to use and it uses Corona's easing transitions. time = 1000, -- defaults to 1000 (milliseconds, 1000 = 1 sec) }, callBackData = { sceneDestination = "fun", -- internal helper for scene switching sceneTransitionColor = { 0, 0.73, 1 }, -- RGB(A) color for transition, sceneTransitionAnimation = true } }) --Cancel button mui.newRoundedRectButton({ name = "cancelButton", text = "CANCEL", width = mui.getScaleVal(180), height = 36, radius = 2, textMargin = 16, x = display.contentWidth - 16 - ((mui.getScaleVal(180)/2) \* 3) - 8, y = ((origin + ((mui.getWidgetProperty("Contact", "label").height) \* 2)) \* 3.5), font = composer.getVariable("defaultItemFont"), fillColor = { 1, 1, 1, 1 }, textColor = composer.getVariable("mainColor"), touchpoint = false, callBack = closeThis, --called when cancel button is clicked animation = { animationType = "colorTransition", -- the only animation type at this time. transitionStartColor = {0.88,0.88,0.88,1}, -- RGB(A) color in percent transitionEndColor = { 1, 1, 1, 1 }, -- RGB(A) color in percent transition = easing.inOutExpo, -- transition to use and it uses Corona's easing transitions. time = 1000, -- defaults to 1000 (milliseconds, 1000 = 1 sec) } }) sceneGroup:insert( background ) end function scene:show( event ) local sceneGroup = self.view local phase = event.phase if phase == "will" then print("add show will") elseif phase == "did" then print("add show did") end end function scene:hide( event ) local sceneGroup = self.view local phase = event.phase local parent = event.parent if event.phase == "will" then print("add hide will") elseif phase == "did" then print("add hide did") mui.destroy() end end function scene:destroy( event ) local sceneGroup = self.view print("add destroy") mui.destroy() end --------------------------------------------------------------------------------- -- Listener setup scene:addEventListener( "create", scene ) scene:addEventListener( "show", scene ) scene:addEventListener( "hide", scene ) scene:addEventListener( "destroy", scene ) ----------------------------------------------------------------------------------------- return scene

And this is how I show the Overlay:

local function handleButtonEvent( event ) if ( "ended" == event.phase ) then print( "Button was pressed and released" ) composer.showOverlay( "add", { isModal = true }) end end --add.lua being the name of the overlay

I’d really appreciate some help with this, I’ve been on it for hours. Thank you!

Try adding:

composer.removeScene("add")

just before you call the composer.showOverlay() call.

Rob

It’s not working, it still shows the setFillColor error on the second try,any other advice?

Update: I tried making the overlay a scene, and it showed the same error, then I tried figuring out a way to do everything within the previous scene without needing to call an overlay or scene, in other words, making add.lua unnecessary but it showed the same error, I’m beginning to think it has something to do with the mui plugin, anyone know how I can troubleshoot this?

Update: I tried using the github version of the mui instead, I still get the error but I have something more tangible, it shows:

[directory]\materialui\mui-base.lua:633: attempt to call method 'setFillColor' (a nil value) 21:34:18.672 stack traceback: 21:34:18.672 [directory]\materialui\mui-base.lua:633: in function '?' 21:34:18.672 ?: in function \<?:182\>

I still don’t understand what exactly the problem is though, the code is really long so I’ll just link to it https://github.com/arcadefx/material-ui/blob/master/materialui/mui-base.lua

right now it’s the only lead I’ve got

I managed to fix the problem, it was with the mui-base script, I simply added a line in the code somewhere around 636

if(startTime + length > runTime) then

if params.fillType == nil then

displayObj:setFillColor(unpack(colorInterpolate(params.startColor, params.endColor, runTime-startTime, length)))

else

displayObj:setStrokeColor(unpack(colorInterpolate(params.startColor, params.endColor, runTime-startTime, length)))

end

Runtime:removeEventListener(“enterFrame”, displayObj.runFunc) --this line was added

else

I’m glad you resolved it.

Rob

Thanks!

Try adding:

composer.removeScene("add")

just before you call the composer.showOverlay() call.

Rob

It’s not working, it still shows the setFillColor error on the second try,any other advice?

Update: I tried making the overlay a scene, and it showed the same error, then I tried figuring out a way to do everything within the previous scene without needing to call an overlay or scene, in other words, making add.lua unnecessary but it showed the same error, I’m beginning to think it has something to do with the mui plugin, anyone know how I can troubleshoot this?

Update: I tried using the github version of the mui instead, I still get the error but I have something more tangible, it shows:

[directory]\materialui\mui-base.lua:633: attempt to call method 'setFillColor' (a nil value) 21:34:18.672 stack traceback: 21:34:18.672 [directory]\materialui\mui-base.lua:633: in function '?' 21:34:18.672 ?: in function \<?:182\>

I still don’t understand what exactly the problem is though, the code is really long so I’ll just link to it https://github.com/arcadefx/material-ui/blob/master/materialui/mui-base.lua

right now it’s the only lead I’ve got

I managed to fix the problem, it was with the mui-base script, I simply added a line in the code somewhere around 636

if(startTime + length > runTime) then

if params.fillType == nil then

displayObj:setFillColor(unpack(colorInterpolate(params.startColor, params.endColor, runTime-startTime, length)))

else

displayObj:setStrokeColor(unpack(colorInterpolate(params.startColor, params.endColor, runTime-startTime, length)))

end

Runtime:removeEventListener(“enterFrame”, displayObj.runFunc) --this line was added

else

I’m glad you resolved it.

Rob

Thanks!