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 try to load addon before it import it all resources. #39313

Open
Jeremi360 opened this issue Jun 5, 2020 · 4 comments
Open

Godot try to load addon before it import it all resources. #39313

Jeremi360 opened this issue Jun 5, 2020 · 4 comments

Comments

@Jeremi360
Copy link

Godot version:
3.2.1

OS/device including version:
Ubuntu 20.04, Windows 10

Issue description:
So I making addon with a lot of resources called Rakugo.
And I publish template project that use it.
When people try to open it for first time it crashes Godot with bug simmilar this:

ERROR: Failed loading resource: res://.import/sound-on.png-c7069ca607a583f763fc164615f5a3ee.stex.
   At: core/io/resource_loader.cpp:278
ERROR: Failed loading resource: res://gui/OptionsBox/icons/sound-on.png.
   At: core/io/resource_loader.cpp:278
ERROR: _load_data: Condition "!f" is true. Returned: ERR_CANT_OPEN
   At: scene/resources/texture.cpp:502
ERROR: Failed loading resource: res://.import/sound-on.png-c7069ca607a583f763fc164615f5a3ee.stex.
   At: core/io/resource_loader.cpp:278
ERROR: Failed loading resource: res://gui/OptionsBox/icons/sound-on.png.
   At: core/io/resource_loader.cpp:278
WARNING: _parse_ext_resource: Couldn't load external resource: res://gui/OptionsBox/icons/sound-on.png
     At: scene/resources/resource_format_text.cpp:175
ERROR: _load_data: Condition "!f" is true. Returned: ERR_CANT_OPEN
   At: scene/resources/texture.cpp:502
ERROR: Failed loading resource: res://.import/rakugo_var_h_slider.svg-078a6aa2c49fda8df315869911b0f882.stex.
   At: core/io/resource_loader.cpp:278
ERROR: Failed loading resource: res://addons/Rakugo/icons/rakugo_var_h_slider.svg.
   At: core/io/resource_loader.cpp:278
WARNING: _parse_ext_resource: Couldn't load external resource: res://addons/Rakugo/icons/rakugo_var_h_slider.svg
     At: scene/resources/resource_format_text.cpp:175
ERROR: _load_data: Condition "!f" is true. Returned: ERR_CANT_OPEN
   At: scene/resources/texture.cpp:502

But when they try to open it once again every thing works fine.

Steps to reproduce:

  1. Download attached zip project
  2. Try to open in Godot
  3. If it crashes try to reopen the project

Minimal reproduction project:

  1. The empty project just with addon Rakugo-bug-test.zip
  2. The Rakugo Template
@Jeremi360
Copy link
Author

I work around it, by just change all my graphic assets to atlases.
So I can think I can close this bug - nobody bother about this bug anyway.

@follower
Copy link
Contributor

follower commented Jun 17, 2020

@jebedaia360 Using atlases sounds like a useful workaround of the underlying issue--would you be able to give a brief explanation of how you did that?

This seems to be the commit that changed but it wasn't immediately apparent how it worked: rakugoteam/Rakugo-Dialogue-System@87eeaf4

After further reading I'm guessing the relevant part is here: rakugoteam/Rakugo-Dialogue-System@87eeaf4#diff-a72a87a94b7682824d242b0e1358764fL138

So it seems maybe the change to using a .tres adds a level of indirection that results in the load succeeding. Which makes me wonder whether just using an ImageTexture resource file would also work. In which case perhaps the docs just need to be updated to advise against loading an image file directly.

(It's still reasonable to consider the underlying issue an engine bug in need of fixing though--particularly if there's other resources where an equivalent workaround isn't available.)

Edit: Now I'm reminded of it, I guess using an atlas is similar to the approach I took here: follower/godot-camera-plugin-demo@2d7db76#diff-d749e27f47e3083735056a69118dc89f but with the key difference that there's no direct loading of the .png file:

diff --git a/addons/godot-camera-plugin.funabab/plugin.gd b/addons/godot-camera-plugin.funabab/plugin.gd
index f93656b..3a42c89 100644
--- a/addons/godot-camera-plugin.funabab/plugin.gd
+++ b/addons/godot-camera-plugin.funabab/plugin.gd
@@ -5,7 +5,13 @@ const ANDROID_MODULE = "org/godotengine/godot/funabab/camera/FunababCameraPlugin
 const CUSTOM_NODE_NAME = "CameraView";
 
 func _enter_tree():
-	add_custom_type(CUSTOM_NODE_NAME, "Control", preload("camera_view.gd"), preload("icon_node.png"));
+	var custom_icon: Image = Image.new()
+	custom_icon.load("res://addons/godot-camera-plugin.funabab/icon_node.png")
+
+	var custom_icon_texture: ImageTexture = ImageTexture.new()
+	custom_icon_texture.create_from_image(custom_icon)
+
+	add_custom_type(CUSTOM_NODE_NAME, "Control", preload("camera_view.gd"), custom_icon_texture);
 	pass
 
 func _exit_tree():

(As I recall my patch prevented errors on load but still didn't display the texture correctly when first opened.)

@Jeremi360
Copy link
Author

Jeremi360 commented Jun 17, 2020

It's still reasonable to consider the underlying issue an engine bug in need of fixing though--particularly if there's other resources where an equivalent workaround isn't available.

@follower Yes you are right, so I reopen this issue .

Using atlases sounds like a useful workaround of the underlying issue--would you be able to give a brief explanation of how you did that?

Yes, so I use TexturePacker and their plugin to generate atlases and tres files, but to use TexturePacker with godot you need to buy license or use in 7days trial.

Also you don't need to use add_custom_type() at all you can just in your camera_view.gd do this:

extends Control
class_name CameraView, "res://addons/godot-camera-plugin.funabab/icon_node.png"

# it works also with *.tres files

@Jeremi360
Copy link
Author

@follower I was wrong class_name don't work with *.tres files :(

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants