EDIT2: After forwarding this message to the bug report, Corona team has been fixed this issue in the latest daily build (819).
EDIT: After further debugging, i found out that require “widget” is causing this error. See sample code below. Is this a bug caused by widget? Is there any workaround?
Full Error:
Runtime error
bad argument #-1 to '?' (Proxy expected, got nil)
stack traceback:
[C]: ?
[C]: in function '?'
?: in function 'removeSelf'
?: in function 'remove'
Steps to reproduce: (Daily Build 799 & 813)
- Copy paste the below code, main.lua and oc.lua
- You will need to create 2 image and save it as redapple.png(any size) and btn.png (100x40pixel)
- Run it the first time. Remove the object by clicking on the red square on screen.
- Click anywhere on screen to remove. It shouldn’t show error.
- Now relaunch the program and uncomment require “widget” and “button = widget.newButton…”
- Click the red square to remove it.
- now click the screen or the button, you will get this error: bad argument #-1 to ‘?’ (Proxy expected, got nil)…
-- main.lua
local oc = require "oc"
--local widget = require "widget"
local remove = display.remove
local apple
local button
local function removeOBJ()
remove( apple )
return true
end
local function deleteOBJ( event )
if event.phase == "ended" then
print( "removed from main.lua" )
remove( apple )
end
return true
end
local function spawnObj()
apple = oc.makeObj( "redapple.png" )
apple.x = display.contentWidth / 2
apple.y = display.contentHeight / 2
--[[
button = widget.newButton{
label = "remove",
default = "btn.png",
over = "btn.png",
width = 100,
height = 40,
onRelease = removeOBJ
}
]]--
end
local function main()
spawnObj()
Runtime:addEventListener( "touch", deleteOBJ )
end
main()
-- oc.lua
local OC = {}
local function removeOBJ( event )
if event.phase == "ended" then
print( "removed from oc.lua" )
display.remove( event.target )
end
return true
end
local function createOBJ( name )
local obj = display.newGroup()
local img = display.newImage( name )
obj:insert( img )
img = nil
obj:addEventListener( "touch", removeOBJ )
return obj
end
OC.makeObj = createOBJ
return OC
=============================================================
IGNORE THE BELOW (Posted before i found the bug) SEE ABOVE ^^^^
I read somewhere in corona blog that display.remove() is a safer way than removeSelf() because display.remove() will check if the object has already been remove and then it will call removeSelf().
But currently in my situation, i am experiencing a weird problem that i can’t debug and reproduce.
I am on my 2nd day of trying to find the problem but it is driving me nuts ]:
Here is the full error:
Runtime error
bad argument #-1 to '?' (Proxy expected, got nil)
stack traceback:
[C]: ?
[C]: in function '?'
?: in function 'removeSelf'
?: in function 'remove'
What could possibly be wrong when display.remove() gives me this error when display.remove() checks if the object is already remove before calling removeSelf()?
The error shows up when i remove the object by clicking the apple itself (removed from oc.lua)
and then i click the button on main.lua.
My code:
-- main.lua
local oc = require "oc"
local widget = require "widget"
local remove = display.remove
local apple
local button
local function removeOBJ()
remove( apple )
return true
end
local function spawnOBJ()
apple = oc.makeOBJ( "redapple.png" )
apple.x = display.contentWidth / 2
apple.y = display.contentHeight / 2
button = widget.newButton{
label = "remove",
default = "btn.png",
over = "btn.png",
width = 100,
height = 40,
onRelease = removeOBJ
}
end
local function main()
spawnOBJ()
end
main()
-- oc.lua
local OC = {}
local function removeOBJ( event )
if event.phase == "ended" then
display.remove( event.target )
end
return true
end
local function createOBJ( name )
local obj = display.newGroup()
local img = display.newImage( name )
obj:insert( img )
img = nil
obj:addEventListener( "touch", removeOBJ )
return obj
end
OC.makeOBJ = createOBJ
return OC
Please help. I don’t know what i am missing [import]uid: 74723 topic_id: 26241 reply_id: 326241[/import]