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

Godot 4.3 GDScript export mode breaks exported builds with some addons. #94150

Closed
shomykohai opened this issue Jul 9, 2024 · 8 comments
Closed

Comments

@shomykohai
Copy link

Tested versions

Reproducible in Godot 4.3 beta1 and beta2

System information

Windows 11 - Godot 4.3 beta2 - Any Renderer

Issue description

On Godot 4.3 beta1, the option to compile GDScript code on exported builds got reintroduced.
I'm using @bitbrain's Pandora addon, and I encountered a bug regarding this option:
The addon allows to declare RPG data and then later access it.
Pandora Editor

When running the project from the editor, everything works as it should, and I can load the png file into a TextureRect
Editor Screen

However, if the GDScript export mode is set to binary tokens/compressed binary tokens, the texture won't load:
Exported Build compressed
And the console output is
Console output

Finally, setting the GDScript export mode to text makes the texture load.

This is the workaround, that only fixes the issue on builds with compiled gdscript files.
bitbrain/pandora#189

Steps to reproduce

  • Open the MRP attached and run it in the Editor -> The Godot Icon should be loaded into the TextureRect
  • Export the project setting GDScript export mode either on Compressed binary tokens or Binary tokens -> The Godot Icon won't load and an error should appear in the console (String to Resource casting)
  • Export the same project but with GDScript export mode on Text -> The Godot icon is loaded into the TextureRect.

Minimal reproduction project (MRP)

issue.zip

@akien-mga akien-mga added this to the 4.3 milestone Jul 10, 2024
@github-project-automation github-project-automation bot moved this to For team assessment in GDScript Issue Triage Jul 10, 2024
@dalexeev dalexeev moved this from Unassessed to Release Blocker in 4.x Release Blockers Jul 12, 2024
@dalexeev dalexeev moved this from For team assessment to Up for grabs in GDScript Issue Triage Jul 12, 2024
@HolonProduction
Copy link
Member

Pandora dynamically loads type loader scripts to handle certain stuff. If the type loader for resources is valid it loads the resource at the given path which returns the texture. If not it falls back to just returning the string instead of loading it. (and then casting this string to a resource will result in null as texture)

The condition used to determine whether the loader is valid is the following:
ScriptType != null and ScriptType.has_source_code()

GDScripts with binary tokens return false when calling has_source_code, thus pandora deems the correctly loaded script as invalid and falls back to not loading the resource.

The question is. Is this an issue on our side or should this be fixed in the addon? I'd say returning true in this case wouldn't be correct and confusing. The better way to fix this, would be replacing has_source_code with can_instantiate in the add-on.

@bitbrain
bitbrain/pandora#188 fixed a similar issue by just removing the check altogether. Maybe this can be done in type.gd in the same way?

@HolonProduction
Copy link
Member

We should probably document this as note on Script.has_source_code (I know it's GDScript specific but at any other place it would get lost)

@shomykohai
Copy link
Author

Pandora dynamically loads type loader scripts to handle certain stuff. If the type loader for resources is valid it loads the resource at the given path which returns the texture. If not it falls back to just returning the string instead of loading it. (and then casting this string to a resource will result in null as texture)

The condition used to determine whether the loader is valid is the following: ScriptType != null and ScriptType.has_source_code()

GDScripts with binary tokens return false when calling has_source_code, thus pandora deems the correctly loaded script as invalid and falls back to not loading the resource.

The question is. Is this an issue on our side or should this be fixed in the addon? I'd say returning true in this case wouldn't be correct and confusing. The better way to fix this, would be replacing has_source_code with can_instantiate in the add-on.

@bitbrain bitbrain/pandora#188 fixed a similar issue by just removing the check altogether. Maybe this can be done in type.gd in the same way?

I can confirm that applying this changes to Pandora fixes the issue with binary tokens.

We should probably document this as note on Script.has_source_code (I know it's GDScript specific but at any other place it would get lost)

My guess is that with the current implementation of GDScript, the has_source_code works only with plain source code.
Surely the documentation has to be updated, as this could lead to bugs on exported builds considering that the export mode is set to binary tokens by default.

Making it return true wouldn't make sense, as it would lead people to think that they can get the source code only to be presented with an empty string.

@HolonProduction
Copy link
Member

Maybe something in the vain of

Note: just because a Script does not have source code, does not mean, that it is invalid or unusable. For example GDScripts that are exported with binary tokenization don't have source code but can still be instantiated and behave as expected.

@akien-mga akien-mga moved this from Release Blocker to Bad in 4.x Release Blockers Jul 18, 2024
@shomykohai
Copy link
Author

Maybe something in the vain of

Note: just because a Script does not have source code, does not mean, that it is invalid or unusable. For example GDScripts that are exported with binary tokenization don't have source code but can still be instantiated and behave as expected.

I'd include a suggestion to use 'can_instantiate()` for cases where someone needs to check if the script is valid, to avoid cases like Pandora.

@HolonProduction
Copy link
Member

HolonProduction commented Jul 19, 2024

#94527 adds documentation for that.

I'd also open a PR against pandora with the fix but it doesn't work right now.
In the MRP exchanging has_source_code with can_instantiate works just fine. However applying this to the current master of the padora addon doesn't seem to work. Another bug was introduced on their side, which persists the property before running the game roughly as
{"type": "undefined", "value": "<CompressedTexture#84384>"} where it should be {"type": "resource", "value": "res://godot.png"}
Someone who actually understands the addon will have to deal with that.

Edit: Or maybe that's just an incompatibility between the mrp and the current state of pandora 🤷

@shomykohai
Copy link
Author

#94527 adds documentation for that.

I'd also open a PR against pandora with the fix but it doesn't work right now. In the MRP exchanging has_source_code with can_instantiate works just fine. However applying this to the current master of the padora addon doesn't seem to work. Another bug was introduced on their side, which persists the property before running the game roughly as {"type": "undefined", "value": "<CompressedTexture#84384>"} where it should be {"type": "resource", "value": "res://godot.png"} Someone who actually understands the addon will have to deal with that.

Edit: Or maybe that's just an incompatibility between the mrp and the current state of pandora 🤷

I'm thinking of it being an addon issue too, getting this with master too (applying the can_instantiate fix).
issue

At least we've confirmed it not to be a Godot related issue.

@akien-mga
Copy link
Member

akien-mga commented Jul 19, 2024

I'd suggest opening an issue on https://github.com/bitbrain/pandora since it's been confirmed not to be a Godot bug, but an addon-specific one.

Thanks everyone for the work debugging this!

@github-project-automation github-project-automation bot moved this from Up for grabs to Done in GDScript Issue Triage Jul 19, 2024
@akien-mga akien-mga removed this from the 4.3 milestone Jul 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Archived in project
Development

No branches or pull requests

6 participants