[Resolved] display.remove() giving error: bad argument #-1 to '?' (Proxy expected, got nil)...

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)

  1. Copy paste the below code, main.lua and oc.lua
  2. You will need to create 2 image and save it as redapple.png(any size) and btn.png (100x40pixel)
  3. Run it the first time. Remove the object by clicking on the red square on screen.
  4. Click anywhere on screen to remove. It shouldn’t show error.
  5. Now relaunch the program and uncomment require “widget” and “button = widget.newButton…”
  6. Click the red square to remove it.
  7. 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]

Sorry for bumping. But i am currently stuck with this and hope there is a solution to bypass this problem. [import]uid: 74723 topic_id: 26241 reply_id: 106578[/import]

My guess here is something in the widget library is superceding the display.remove code, causing it to not check if the object is actually nil. Just change your remove override to handle this yourself. Then you don’t depend on display.remove to check for you.

local function remove(obj) if obj ~= nil then obj:removeSelf() end end [import]uid: 56820 topic_id: 26241 reply_id: 106665[/import]

EDIT: This issue has been fix in the latest daily build (819). See above

Switching all to removeSelf gives me another crash. Not sure why it even when i check for if obj ~= nil. My current workaround is to create my own custom button class that handles itself. [import]uid: 74723 topic_id: 26241 reply_id: 106699[/import]