ContentActionService Client CRASH

Binding a key to a function which then immediately binds the same key to another function crashes the client.

*putting a wait before the rebinding of the key prevents the crash

See here, local script inside Player GUI.

Join the game and press K, client crashes.

Taking a look at this, thanks for the report!

I used to do this in Script Builder to people who automatically re-instantiated something whenever it got deleted. I fired my laser at it which ran on the server and they disconnected when they created a new one on their client and it got destroyed right after. Is this that?

IDK, this is the code for the bug I found:

[code]local CAS = game.ContextActionService

function f1()
CAS:BindActionToInputTypes(“f2”, f2, false, Enum.KeyCode.K)
end

function f2()

end

CAS:BindActionToInputTypes(“f1”, f1, false, Enum.KeyCode.K)[/code]

repro…
http://developer.roblox.com/forum/development-discussion/14883-roblox-game-performance-affected-in-recent-update#160575

Alright, sorry it took me so long to get back on this.

This behavior makes some sense, at least for the example shown in the first post (thanks Kevin!). The code looks as follows (I edited it slightly, still produces the crash though):

[code]
local CAS = game.ContextActionService

function f1()
print(“f1”)
CAS:BindAction(“f2”, f2, false, Enum.KeyCode.K)
end

function f2()
print(“f2”)

end

CAS:BindAction(“f1”, f1, false, Enum.KeyCode.K)[/Code]

This essentially results in a stack overflow. This is because when you press down on K it immediately binds K to f2, which causes f1 to receive a cancel event, which then binds to f2, which sends a cancel event to f1, and so on and so forth. We have updated the wiki with better documentation on ContextActionService, and essentially you should pay attention to the parameters being passed into both f1 and f2. Here is a code example that does not crash and probably does what you want.

[Code]
local CAS = game.ContextActionService

function f1(name, state, inputObject)
if state == Enum.UserInputState.Begin then
print(“f1”)
CAS:BindAction(“f2”, f2, false, Enum.KeyCode.K)
elseif state == Enum.UserInputState.Cancel then
print(“f1 has been cancelled”)
end
end

function f2(name, state, inputObject)
print(“f2”, name, state, inputObject)

end

CAS:BindAction(“f1”, f1, false, Enum.KeyCode.K)[/Code]

If you press K in this example, the output will be:
f1
f1 has been cancelled
f2 f2 Enum.UserInputState.End InputObject

Hopefully that clears some stuff up, if not please feel free to ask.