how to debug error that only shows up on device

I’m using the tiltmonster template. On the simulator everything works fine. On device however the game never completely loads.
On the device console when attached via USB I get the following error:

Jan 5 12:17:09 unknown UIKitApplication:MonstaMayhem[0x5d57][15337] : Lua Runtime Error: lua_pcall failed with status: 2, error message is: ERROR: table expected. If this is a function call, you might have used ‘.’ instead of ':'

How do I debug something like this when it only fails on device. (Tested on gen1 Ipad 5.0.1 gen2 Ipod 4.2.1, Iphone 3g 4.2.1, Iphone 4 5.0.1)

[import]uid: 9035 topic_id: 19973 reply_id: 319973[/import]

it can be one of the external libraries, try to remove them and launch app [import]uid: 16142 topic_id: 19973 reply_id: 77769[/import]

I have this exact same problem. My app works on my iPod Touch, but shows a blank screen on iPhone 3GS.

The error message is:

lua_pcall failed with status: 2, error message is: ERROR: table expected. If this is a function call, you might have used ‘.’ instead of ‘:’

Which external libraries should I look out for?

I’ve built using Corona Version 2012.819 (2012.12.8).

I’m not using any external library in my app.

Thanks,
Kapil [import]uid: 135671 topic_id: 19973 reply_id: 108099[/import]

EEEEK!!! The dreaded pcall error!

This is a tough one to debug for sure. I’ve had it and it greyed me.

My problem was being generated from an external lib.

It took me a FULL day to figure out what was causing it to be kicked on Device. There is very little info about the pcall error available as I’m sure you know.

I agree with the poster above to start removing external libs until the error disappears. I did not know this when I was debugging the error, although through trial and elimination I eventually adopted this method.

Unfortunately for me, I started by commenting out blocks of my code until I basically had none left, thinking it MUST be my code causing the problem, surely not one of the readily available and popular libs that many others use.

Well, when I had nothing left of my code, I started removing the external libs and discovered my pcall error was being kicked by json.lua. Ya, how about that. There wasn’t a single reference tying the pcall error to json anywhere.

Moving on, when I tracked the problem to json.lua, it atleast game me an avenue to begin researching and found a thread describing how json.lua is being depricated and replaced by dkjson.lua. Do a Google search to get the file.

Replacing json.lua with the newer version solved my issue. I’m sure I’m not the only noob that has experienced a very frustrating day discovering the culprit kicking the pcall error.

If you require json.lua, I would start there. If not, I’d start eliminating external libs until the error disappears.

If you don’t require any external libs, I’m don’t know what to say. I guess it must be your code, but who knows.

Hope this helps anyone experiencing a pcall error on device, the simulator and none of the debuggers at the time caught this btw.

GL [import]uid: 106779 topic_id: 19973 reply_id: 108214[/import]

Aha! Thanks xnailbender! That does give me a direction.

Now I remember that a while back when I was using an older Corona build, I did read that they are moving from json.lua to dkjson.lua. And for some error that I was facing, I decided to just put dkjson.lua in my project folder and use that instead the “built-in at that time” json.lua.

Hmmm. Now I have updated to the latest daily build and I am guessing that this build already includes dkjson.lua in the SDK? Need to read up on this. If this is the case, then I have one version of dkjson in Corona SDK and one version in my code files. That might be causing some kind of conflict.

Thanks again, I will try to read up on this and will post an update here.

Kapil [import]uid: 135671 topic_id: 19973 reply_id: 108221[/import]

The latest builds are using dkjson. [import]uid: 84637 topic_id: 19973 reply_id: 108245[/import]

Yes so I removed the dkjson.lua which I had in my code folder, and changed all require(“dkjson”) to require(“json”). That didn’t solve the problem for me.

Then I chopped through my code bit by bit, and now I’ve narrowed it down to group:insert().

So I wrote another simple app just to test if I get consistent behavior. This test app does nothing other than:

  1. io.output():setvbuf(‘no’) – **debug: disable output buffering for Xcode Console
  2. require storyboard
  3. hide status bar (the iPhone status bar on top)
  4. go to a scene

The scene simply displays a full screen splash image:

[lua]local storyboard = require( “storyboard” )
local scene = storyboard.newScene()
local blah

function scene:createScene( event )
local group = self.view

print(“splashscene create event”)

print(“drawing splash image”)
blah = display.newImageRect( “assets/splash.png”, display.contentWidth, display.contentHeight )
print(“inserting in group”)
group:insert(blah)
print(“setting x”)
blah.x = display.contentWidth/2
print(“setting y”)
blah.y = display.contentHeight/2

print(“out of splash create event”)
end[/lua]

No problem on simulator. No problem on iPod Touch.
Error on iPhone 3GS:
[text]
May 23 23:53:34 unknown UIKitApplication:xxx.xxx.xxx[0xfaf5][211] : imported storyboard
May 23 23:53:34 unknown UIKitApplication:xxx.xxx.xxx[0xfaf5][211] : status bar hidden
May 23 23:53:34 unknown UIKitApplication:xxx.xxx.xxx[0xfaf5][211] : splashscene create event
May 23 23:53:34 unknown UIKitApplication:xxx.xxx.xxx[0xfaf5][211] : drawing splash image
May 23 23:53:34 unknown UIKitApplication:xxx.xxx.xxx[0xfaf5][211] : inserting in group
May 23 23:53:34 unknown UIKitApplication:xxx.xxx.xxx[0xfaf5][211] : Lua Runtime Error: lua_pcall failed with status: 2, error message is: ERROR: table expected. If this is a function call, you might have used ‘.’ instead of ‘:’
[/text]
[import]uid: 135671 topic_id: 19973 reply_id: 108301[/import]

Hey Danny,

When I struggled with the pcall error, the simulator did not kick an error/warning that I had json.lua in my project folder instead of dkjson.lua. Not sure if this warning has been added to the simulator yet, which would have been nice at the time.

Even though the latest builds use dkjson, if the actual dkjson.lua file is not placed in the project file, the user will kick the error I believe.

Just to clarify, I replaced the json.lua file with dkjson.lua and changed the require declaration to:

json = require( “dkjson”)

I did not declare it “local” as I have other external modules coded by others that do not declare it “local”, so I left it as is. [import]uid: 106779 topic_id: 19973 reply_id: 108308[/import]

@kapil.pendse

I haven’t played with “storyboard” yet and as a newbe, I’m out of my league anyways, but would it make a difference if…

group:insert() was placed after the blah coordinate declaration?

Bummed to hear changing dkjson.lua didn’t solve your problem, I’m thinking it probably needed to be changed eventually though and hopefully wasn’t a waste of time for you.

GL [import]uid: 106779 topic_id: 19973 reply_id: 108315[/import]

@xnailbender, your suggestion gave me a direction to look so it was definitely welcome :slight_smile:

Well I don’t think you need to have dkjson.lua file in your code folder. It is now part of Corona SDK. So just a:
local json = require(“json”)
should be sufficient.

Note that earlier I was using an older build of Corona which did NOT have dkjson built-in. It was using another JSON library which didn’t seem to work for me. So I had manually dropped in dkjson.lua. You don’t need to do that any more. Sorry for the confusion.

But good news.

I found this: http://developer.anscamobile.com/forum/2012/05/05/critical-bug-805

Although not exactly same problem, I thought worth a try. So tested my example code (in earlier post) with Corona build 821. Same problem. Reverted to Corona build 799.

WORKS!!!

Then built my full app, and that also works :slight_smile:

So, should I file a bug report against the latest build?

@Danny, could you please comment?

Thanks!
Kapil [import]uid: 135671 topic_id: 19973 reply_id: 108316[/import]