Using task.defer’s re-entrancy depth limit, or a C stack overflow, certain events can be stopped from firing.
- Repro file (Deferred events): Place1.rbxl (52.8 KB)
- Repro file not provided for C Stack Overflow. It crashes Studio, but works in live games.
Deferred events:
Show
workspace.DescendantAdded:Connect(function(NewInstance)
if NewInstance:IsA("BoxHandleAdornment") then
print(NewInstance) -- should print new Instances
end
end)
local Depth = 80 -- Maximum re-entrancy depth for task.defer
local currentDepth = 0
local Defer; Defer = function()
currentDepth += 1
if currentDepth == Depth then
Instance.new("BoxHandleAdornment", workspace)
-- maximum re-entrance depth prevents roblox's deferred
-- event from deferring properly, effectively cancelling it.
else
task.defer(Defer)
end
end
Defer()
Immediate events:
Show
workspace.DescendantAdded:Connect(function(NewInstance)
if NewInstance:IsA("BoxHandleAdornment") then
print(NewInstance) -- should print new Instances
end
end)
local Stack; Stack = function()
if coroutine.status(task.spawn(Stack)) == "dead" then
return
end
Instance.new("BoxHandleAdornment", workspace)
-- print connection does not fire
end
Stack()
You can also do this with a BindableFunction:
workspace.DescendantAdded:Connect(function(NewInstance)
if NewInstance:IsA("BoxHandleAdornment") then
print(NewInstance) -- should print new Instances
end
end)
local Bindable = Instance.new("BindableFunction")
Bindable.OnInvoke = function()
if pcall(Bindable.Invoke, Bindable) == false then
Instance.new("BoxHandleAdornment", workspace)
-- print connection does not fire
end
end
pcall(Bindable.Invoke, Bindable)
Expected behavior
I expect roblox’s events to fire regardless of the status of the script causing them.