Skip to content

Conversation

@XeduR
Copy link

@XeduR XeduR commented Nov 24, 2022

There's currently a chance that the button's touch event is still called after the button's view.parent has already been removed and set to nil. This will result in a runtime error within function widget._isWithinBounds( object, event ) when it attempts to index a nil value (i.e. object.contentBounds within object as it isn't a table anymore).

function widget._isWithinBounds( object, event )
local bounds = object.contentBounds
local x, y = event.x, event.y
local isWithinBounds = true
if "table" == type( bounds ) then
if "number" == type( x ) and "number" == type( y ) then
isWithinBounds = bounds.xMin <= x and bounds.xMax >= x and bounds.yMin <= y and bounds.yMax >= y
end
end
return isWithinBounds
end

The safest and easiest way to fix this issue is to just check that the button's view.parent exists and is still a display object at the start of the touch listener.

As a part of these changes, there's no need for further checks to see if the parent view exists given that the function won't get past the new initial check if it doesn't.

There's currently a chance that the button's touch event is still called after the button's `view.parent` has already been removed and set to nil. This will result in a runtime error within `function widget._isWithinBounds( object, event )` when it attempts to index a nil value (i.e. `object.contentBounds` within `object` as it isn't a table anymore).

https://github.com/coronalabs/framework-widget/blob/d425ae72f47b29a3da5880eebcb1111f2cdf6cd2/widgetLibrary/widget.lua#L245-L257

The safest and easiest way to fix this issue is to just check that the button's `view.parent` exists and is still a display object at the start of the touch listener.

As a part of these changes, there's no need for further checks to see if the parent view exists given that the function won't get past the new initial check if it doesn't.
@XeduR
Copy link
Author

XeduR commented Dec 7, 2022

Could you take a look at this PR @Shchvova?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant