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

can't hold resource?!?!?!? #41

Closed
BestestHD opened this issue Jul 14, 2022 · 4 comments · Fixed by #59
Closed

can't hold resource?!?!?!? #41

BestestHD opened this issue Jul 14, 2022 · 4 comments · Fixed by #59
Assignees
Labels
bug Something isn't working

Comments

@BestestHD
Copy link

BestestHD commented Jul 14, 2022

pretty big issue i've been running into, it's seemingly impossible to load resources.
i print the resource and godot just says [Object:null]
here's my sample code

local bgImg
bgImg = load_texture("res://gfx/tex/bg/tex_bg_terminal_room.png")
print(bgImg)

load_texture returns a Texture2D, though no resource i've tried works. i haven't tried custom resource yet but that would be seriously damning, for the texture example i can just write a function that returns a sprite and loads the texture from the path onto the TextureRect's texture property but that isn't always an option for some of my game's resources.

please tell me if it works on your end, for all i know it's just because my build of godot 4 is a little out of date 😅 (waiting until a few specifics PRs are merged...)

@BestestHD
Copy link
Author

ok i realized that the issue is that reference-counting doesn't work for lua vars, pushing the resource into a reference array works as the resource stays referenced in gdscript.
so change the issue to references i guess, i imagine this should(?) be trivial to fix

@Trey2k
Copy link
Member

Trey2k commented Jul 14, 2022

While in theory this should work godot gets touchy when it dosnt own the memory. I will need to do some testing to figure out what the best method of resource loading from lua would be. In a ideal world lua wont own the resource but only have a reference to it. Sometimes lua owning the resource is fine but it also can cause lots of issues.

@Trey2k Trey2k added the bug Something isn't working label Jul 30, 2022
@Trey2k Trey2k added this to To do in v2 for godot v4 Nov 3, 2022
@Trey2k Trey2k self-assigned this Jan 14, 2023
@Trey2k Trey2k moved this from To do to In progress in v2 for godot v4 Jan 14, 2023
@Trey2k
Copy link
Member

Trey2k commented Jan 17, 2023

ok i realized that the issue is that reference-counting doesn't work for lua vars, pushing the resource into a reference array works as the resource stays referenced in gdscript. so change the issue to references i guess, i imagine this should(?) be trivial to fix

As mentioned here the issue is with RefCounted specifically. We currently do not test if the object being passed is a RefCounted or not.

@Trey2k
Copy link
Member

Trey2k commented Jan 18, 2023

I found out we are able to use metatables on lightuserdata. So that is what we are doing.

@Trey2k Trey2k linked a pull request Jan 18, 2023 that will close this issue
@Trey2k Trey2k moved this from In progress to Done in v2 for godot v4 Jan 18, 2023
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
Status: Done
Development

Successfully merging a pull request may close this issue.

2 participants