ILuaBox quit

1 view
Skip to first unread message

Ali Sherif

unread,
Mar 17, 2011, 6:14:58 AM3/17/11
to iLuaBox
iLuaBox quits every time I run the below script:

-- screenbutton.lua

dofile("gui.lua")

function creatview ()
 local v = gui.newView {frame = {origin = {x = 0, y = 70}, size =
{width = 900, height = 500}}, backgroundColor = gui.whiteColor}
gui._BACKGROUND:add(v)

  local b = gui.newButton {frame = {origin = {x = 10, y = 10}, size =
{width = 100, height = 40}}, title = "Exit", buttonType = 1 }
 b.controlEventTouchUpInside = otherClose
 b.titleColor = gui.redColor
v:add(b)
end


function otherClose ()
  v:destroy()
  gui.statusBarHidden = false
  collectgarbage()
end

creatview ()

Thanks

Tom Skwara

unread,
Mar 17, 2011, 12:32:18 PM3/17/11
to ilu...@googlegroups.com
Ok, two issues at hand here:  the first has to do with your code, and the second has to do with a bug in iLuaBox.

'otherClose()' attempts to index a global variable 'v', which is actually declared as local within 'createView()'.  An exception will occur since 'v' doesn't exist anymore in the global table when 'otherClose' fires.  Using 'v' as a global variable (not declaring it local) will keep iLuaBox from exiting.  Also, you can pass a reference to 'v' as a variable indexed to 'b' and retrieve that reference in 'otherClose()'.

Here's a revised version of your code that continues using only local variables:


-- screenbutton.lua

dofile("gui.lua")


function creatview ()
  local v = gui.newView {frame = {origin = {x = 0, y = 70}, size =
    {width = 900, height = 500}}, backgroundColor = gui.whiteColor}

  gui._BACKGROUND:add(v)

  local b = gui.newButton {frame = {origin = {x = 10, y = 10}, size =
    {width = 100, height = 40}}, title = "Exit", buttonType = 1 }

  b.controlEventTouchUpInside = otherClose
  b.titleColor = gui.redColor
  b.viewRef = v  -- new indexes can be added at will for any purpose
  v:add(b)
end


function otherClose (b)  -- optional arg1 is always a reference to sender (i.e. button)
  b.viewRef:destroy()

  gui.statusBarHidden = false
  collectgarbage()
end

creatview ()


Now for the second part.  iLuaBox (up to v1.2.1)  does not properly deal with exceptions that may occur within a callback.  Let's say some code within a callback generates an error (i.e. your original code), iLuaBox catches the error and handles it as if the error occurred within synchronous code.  It attempts to stop program execution and report the error message.  Unfortunately when this is done asynchronously, iLuaBox's multi-threaded code no likey, and crash away we go.

The good news is that the problem has been fixed in the next version (after 1.2.1).  If an error occurs asynchronously (i.e. again, your original code), iLuaBox will print a detailed exception message and return properly from the asynchronous call (i.e. idle mode).

Hopefully my caffeine indulgence this morning hasn't overly complicated this reply, but there you have it!

Tom Skwara
MobileApp Systems



Reply all
Reply to author
Forward
0 new messages