godotengine / godot

Godot Engine – Multi-platform 2D and 3D game engine
https://godotengine.org
MIT License
88.88k stars 20.15k forks source link

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

Open Jeremi360 opened 4 years ago

Jeremi360 commented 4 years ago

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 commented 4 years ago

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 commented 4 years ago

@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: https://github.com/rakugoteam/Rakugo/commit/87eeaf4214331aa119f11f7e4888b53100767b04

After further reading I'm guessing the relevant part is here: https://github.com/rakugoteam/Rakugo/commit/87eeaf4214331aa119f11f7e4888b53100767b04#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: https://github.com/follower/godot-camera-plugin-demo/commit/2d7db76cce767252654771f380a605bde553971b#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 commented 4 years ago

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 commented 4 years ago

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