I keep getting this error...no idea why

This is the error

?:0: attempt to index a nil value stack traceback: ?: in function \<?:1377\> ?: in function 'listener' /Users/jenkins/slaveroot/workspace/Templates/label/android/subrepos/timer/timer.lua:173: in function 'method' /Users/jenkins/slaveroot/workspace/Templates/label/android/platform/resources/init.lua:253: in function \</Users/jenkins/slaveroot/workspace/Templates/label/android/platform/resources/init.lua:221\>

I’m thinking I’m getting it because I was calling timer.cancel on a timer that may not have existed. So I changed my code to the following but it doesn’t seem to have helped any

 

pcall(function() timer.cancel(timerObj) end)

Anyone have any ideas?

Try checking for the timer first.

if( timerObj ) then timer.cancel(timerObj) timerObj = nil -- Next time this will trigger false in check end

Sorry I should have posted the full code this is what I’m using

if(timerObj and not timerObj.\_cancelled) then pcall(function() timer.cancel(timerObj) end) end

Hi.  Sorry, but still not enough info to help.

Let me give some of my usual questions and advice:

  1. What version of Corona are you using (ex: 2015.2625).

  2. Is this ONLY failing on the device?  

  3. If you can’t resolve this by updating the version of Corona you’re using (assuming you’re using something old like  2014.2511 ) then you’ll have to find someone willing to look at the entire project and you’ll need to be willing to share it with them.

  4. How do you know for sure it is that line of code?  i.e. What steps did  you take to debug it to that line?

This error has been showing up for a few months now across multiple daily builds. I can’t replicate it on any device or simulator…but I get about 1,000 of them every day according to gameanalytics. I have no idea that the code I posted is even the problem. The error message is very vague and mentions something about timer.lua which I’m assuming handles the timer commands maybe. It also says it’s nil so I figured maybe the timer object was nil when I was trying to cancel it which led me to that. Once again I really have no idea what is causing this I’ve never seen it on my side. If it was like less then 50 errors total I wouldn’t worry about it but like I said it’s over 1,000 a day now. 

Well, that doesn’t sound at all fun.

Let me ask, just to be sure.  Are you absolutely sure the debug messages you get don’t lead back to a specific file or even line in a file from your app? 

In addition to errors that say, ‘error in this file on line X’, look for more generic ones like ‘error on line X’ without listing a file.  Then, check that line in all of your files (tedious I know).  

Other that than, I wouldn’t normally suggest something this radical, but if all you want to do is quash those errors, try this and see if it helps.

Add this to a module and require it at the top of main.lua:

-- myTimer.lua local lTimer\_cancel = timer.cancel local lTimer\_performWithDelay = timer.performWithDelay local lTimer\_pause = timer.pause local lTimer\_resume = timer.resume timer.cancel = function( timerID ) if( not timerID ) then return end pcall( function() lTimer\_cancel( timerID ) end ) end function timer.cancel( timerID ) if( not timerID ) then return end pcall( function() lTimer\_cancel( timerID ) end ) end function timer.performWithDelay( delay, listener , iterations ) iterations = iterations or 1 if( not delay ) then return end if( not listener ) then return end local success, timerID = pcall( function() return lTimer\_performWithDelay( delay, listener , iterations ) end ) return ( success ) and timerID or nil end function timer.pause( timerID ) if( not timerID ) then return end local success, pauseTime = pcall( function() return lTimer\_pause( timerID ) end ) return ( success ) and pauseTime or nil end function timer.resume( timerID ) if( not timerID ) then return end local success, resumeTime = pcall( function() return lTimer\_resume( timerID ) end ) return ( success ) and resumeTime or nil end

-- In main.lua require "myTimer"

Try checking for the timer first.

if( timerObj ) then timer.cancel(timerObj) timerObj = nil -- Next time this will trigger false in check end

Sorry I should have posted the full code this is what I’m using

if(timerObj and not timerObj.\_cancelled) then pcall(function() timer.cancel(timerObj) end) end

Hi.  Sorry, but still not enough info to help.

Let me give some of my usual questions and advice:

  1. What version of Corona are you using (ex: 2015.2625).

  2. Is this ONLY failing on the device?  

  3. If you can’t resolve this by updating the version of Corona you’re using (assuming you’re using something old like  2014.2511 ) then you’ll have to find someone willing to look at the entire project and you’ll need to be willing to share it with them.

  4. How do you know for sure it is that line of code?  i.e. What steps did  you take to debug it to that line?

This error has been showing up for a few months now across multiple daily builds. I can’t replicate it on any device or simulator…but I get about 1,000 of them every day according to gameanalytics. I have no idea that the code I posted is even the problem. The error message is very vague and mentions something about timer.lua which I’m assuming handles the timer commands maybe. It also says it’s nil so I figured maybe the timer object was nil when I was trying to cancel it which led me to that. Once again I really have no idea what is causing this I’ve never seen it on my side. If it was like less then 50 errors total I wouldn’t worry about it but like I said it’s over 1,000 a day now. 

Well, that doesn’t sound at all fun.

Let me ask, just to be sure.  Are you absolutely sure the debug messages you get don’t lead back to a specific file or even line in a file from your app? 

In addition to errors that say, ‘error in this file on line X’, look for more generic ones like ‘error on line X’ without listing a file.  Then, check that line in all of your files (tedious I know).  

Other that than, I wouldn’t normally suggest something this radical, but if all you want to do is quash those errors, try this and see if it helps.

Add this to a module and require it at the top of main.lua:

-- myTimer.lua local lTimer\_cancel = timer.cancel local lTimer\_performWithDelay = timer.performWithDelay local lTimer\_pause = timer.pause local lTimer\_resume = timer.resume timer.cancel = function( timerID ) if( not timerID ) then return end pcall( function() lTimer\_cancel( timerID ) end ) end function timer.cancel( timerID ) if( not timerID ) then return end pcall( function() lTimer\_cancel( timerID ) end ) end function timer.performWithDelay( delay, listener , iterations ) iterations = iterations or 1 if( not delay ) then return end if( not listener ) then return end local success, timerID = pcall( function() return lTimer\_performWithDelay( delay, listener , iterations ) end ) return ( success ) and timerID or nil end function timer.pause( timerID ) if( not timerID ) then return end local success, pauseTime = pcall( function() return lTimer\_pause( timerID ) end ) return ( success ) and pauseTime or nil end function timer.resume( timerID ) if( not timerID ) then return end local success, resumeTime = pcall( function() return lTimer\_resume( timerID ) end ) return ( success ) and resumeTime or nil end

-- In main.lua require "myTimer"