lune icon indicating copy to clipboard operation
lune copied to clipboard

Creating a new DataModel and setting it as a global called game errors

Open gaymeowing opened this issue 1 year ago • 2 comments

the following code errors with

local roblox = require("@lune/roblox")
game = roblox.Instance.new("DataModel")
thread 'main' panicked at crates\lune-roblox\src\instance\registry.rs:44:17:
cannot mutably borrow app data container

gaymeowing avatar Aug 07 '24 15:08 gaymeowing

I will note I did a quick test of changing the global name to something else, and it didn't error so this weirdly seems to be specific to setting the game global?

gaymeowing avatar Aug 07 '24 15:08 gaymeowing

the issue that youre having is not exactly from those 2 lines of code.

the issue is that in another script (which is being required) youre either trying to get or set a property of game which causes lune to call this function right here https://github.com/lune-org/lune/blob/main/crates/lune-roblox/src/instance/registry.rs#L42 which needs to borrow the app container if the function is called for the first time

[!NOTE] not all properties will cause lune to call this function, so something as simple as game.Name will not call it

the cause of the issue: when a script is in the process of being required, the app data container is borrowed by that require process, so if you use a library that needs the app container, you will get the error.

workaround

the workaround is to somehow call https://github.com/lune-org/lune/blob/main/crates/lune-roblox/src/instance/registry.rs#L42 in your very first script that isnt in the process of being required

the easiest way to do that, is to get/set a property that doesnt exist at all which causes lune to check all alternatives (one of them being the function that we need to call)

local roblox = require("@lune/roblox")
game = roblox.Instance.new("DataModel")

pcall(function()
	return game.Shutdown
end)

-- now you can continue

FlowGnarly avatar Aug 25 '24 11:08 FlowGnarly

Most likely fixed in https://github.com/lune-org/lune/commit/2e5b3bb5eb5356d15b341b46d1a3e2ecaa19ad1c , feel free to reopen after Lune 0.9.3 is out if you can still get it to happen

filiptibell avatar May 02 '25 10:05 filiptibell