Engine events can be suppressed

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.

3 Likes

Thank you for the report.

This is actually working as intended.
When you hit the stack limit, we can no longer resume your script events.
You should work on fixing the errors causing script overflows in your code.

For the Studio crash, we will be working on a fix and will message you when that is deployed!

1 Like

Okay, if I see anybody who has this error in their scripts, I will tell them! :‌)

For the crash, I think it is linked to the output erroring while logging the error, causing another error, and so on, but that’s just a theory…