Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
witchiestwitchery opened this issue Aug 7, 2024 · 2 comments · May be fixed by #247
Open

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

witchiestwitchery opened this issue Aug 7, 2024 · 2 comments · May be fixed by #247
Labels
bug Something isn't working

Comments

@witchiestwitchery
Copy link

witchiestwitchery commented Aug 7, 2024

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
@witchiestwitchery
Copy link
Author

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?

@filiptibell filiptibell added the bug Something isn't working label Aug 7, 2024
@FlowGnarly
Copy link

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 FlowGnarly linked a pull request Aug 25, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants