Button still clickable after returning to scene

I have a scene that has a button and changes between some info pages. The button Is hidden on the second page and is (as expected) not clickable when isVisible = false however. When I move to a new scene, removing the button from it’s group and making it nil in the exit event of the scene. Calling RemoveScene, PurgeScene and any other scene clearing I can imagine. The widget button is now invisible and clickable.

It seems that widget buttons are never actually deleted or removed properly no matter what you do.

Edit: To save all the “Have you tried X and Y” you can test this for yourself by creating a button with an over and default image. add it to a group. add that group to the scene view in enterscene and remove it’s children and then that group in the exitscene (I’m using storyboard). Now simply change to a seemingly empty new scene and voila your button isn’t there but, it’s still clickable. From what I can tell. The reason most people don’t run into this is that they have likely put other groups with event listeners over the button when they have changed scenes and simply haven’t noticed that the previous buttons are still there in ghost form. 

Well if you are doing it right, adding your button to the group and then removing group in exitScene() should work. I had problems with invisible buttons being clickable when I first started using Corona, but this was because I was not adding them to a display group

Edit: Ignore the user name change. My work account is different from my private account.

Nope definitely added to display group and removed at the end and definitely not working. I didn’t notice in my new scene because I have a table and buttons that occupy the space where the phantom button is. So touching there triggers my new scenes listeners . However, when I removed one of the items that was above where the old button lived, that’s when the problem showed itself. Hence my point that the reason most people likely haven’t seen the issue is because the phantom buttons are getting hidden behind object with their own listeners, on scene transition. 

-- Called when scene is about to move offscreen: function scene:exitScene( event ) local group = self.view print("Exit Scene Info") if infoGroup ~= nil then for i = 1, infoGroup.numChildren do local child = infoGroup[i] infoGroup:remove( child ) child = nil end group:remove( infoGroup ) infoGroup = nil end if controlGroup ~= nil then for i = 1, controlGroup.numChildren do local child = controlGroup[i] controlGroup:remove( child ) child = nil end group:remove( controlGroup ) controlGroup = nil end end

OK, well this is the way I remove mine

-- Called when scene is about to move offscreen: function scene:exitScene( event ) local group = self.view display.remove(group) group = nil end

Ok, using a variation of your method I can say that there is definitely an issue with removing widgets the conventional way i.e. if group ~= nil and then the for numb children route.

If I use the normal method I get the widget bug. If I do as you did and remove the scene’s view using display.remove then all is well. So it looks like the issue is that widgets are only removed if you use object.removeself.  

ask:  what’s the value of group.numChildren half-way through your loop?

it’s a common remove-while-iterating problem, try looping backwards: for i=group.numChildren,1,-1 do

Yea sounds like the issue to me. I never did figure out how you were supposed to loop through something that was shrinking at the same time but, silly me, I trusted the example code. :frowning:

I guess it should be using for X in group and not for I < num children

Try this:

for i = yourGroup.numChildren, 1, -1 do display.remove( yourGroup[i] ); yourGroup[i] = nil; end -- and also if you wish.. display.remove( yourGroup ); yourGroup = nil;

Thanks guys.

Yea it looks like the iterate for loop is buggered. The annoying thing is that it doesn’t even throw an error! Yet half way through it’s basically removing nils!

Most consistent method I’ve found is the display.remove method as that will use removeself on the group, which appears to finally delete the widgets. The fact that group:remove(nil) appears to be a valid method call must count as broken though. Or am I being too logical? I mean if remove had simply thrown an error when it got to the nil values then I would have sorted this issue ages ago.

Well if you are doing it right, adding your button to the group and then removing group in exitScene() should work. I had problems with invisible buttons being clickable when I first started using Corona, but this was because I was not adding them to a display group

Edit: Ignore the user name change. My work account is different from my private account.

Nope definitely added to display group and removed at the end and definitely not working. I didn’t notice in my new scene because I have a table and buttons that occupy the space where the phantom button is. So touching there triggers my new scenes listeners . However, when I removed one of the items that was above where the old button lived, that’s when the problem showed itself. Hence my point that the reason most people likely haven’t seen the issue is because the phantom buttons are getting hidden behind object with their own listeners, on scene transition. 

-- Called when scene is about to move offscreen: function scene:exitScene( event ) local group = self.view print("Exit Scene Info") if infoGroup ~= nil then for i = 1, infoGroup.numChildren do local child = infoGroup[i] infoGroup:remove( child ) child = nil end group:remove( infoGroup ) infoGroup = nil end if controlGroup ~= nil then for i = 1, controlGroup.numChildren do local child = controlGroup[i] controlGroup:remove( child ) child = nil end group:remove( controlGroup ) controlGroup = nil end end

OK, well this is the way I remove mine

-- Called when scene is about to move offscreen: function scene:exitScene( event ) local group = self.view display.remove(group) group = nil end

Ok, using a variation of your method I can say that there is definitely an issue with removing widgets the conventional way i.e. if group ~= nil and then the for numb children route.

If I use the normal method I get the widget bug. If I do as you did and remove the scene’s view using display.remove then all is well. So it looks like the issue is that widgets are only removed if you use object.removeself.  

ask:  what’s the value of group.numChildren half-way through your loop?

it’s a common remove-while-iterating problem, try looping backwards: for i=group.numChildren,1,-1 do

Yea sounds like the issue to me. I never did figure out how you were supposed to loop through something that was shrinking at the same time but, silly me, I trusted the example code. :frowning:

I guess it should be using for X in group and not for I < num children

Try this:

for i = yourGroup.numChildren, 1, -1 do display.remove( yourGroup[i] ); yourGroup[i] = nil; end -- and also if you wish.. display.remove( yourGroup ); yourGroup = nil;

Thanks guys.

Yea it looks like the iterate for loop is buggered. The annoying thing is that it doesn’t even throw an error! Yet half way through it’s basically removing nils!

Most consistent method I’ve found is the display.remove method as that will use removeself on the group, which appears to finally delete the widgets. The fact that group:remove(nil) appears to be a valid method call must count as broken though. Or am I being too logical? I mean if remove had simply thrown an error when it got to the nil values then I would have sorted this issue ages ago.