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

Remove incorrect *.import from .gitignore as it breaks plugin & add missing *.import files #1

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

follower
Copy link

@follower follower commented Feb 18, 2020

This PR contains a two step fix--first we fix the .gitignore file & then we add the missing *.png.import files.

If the plugin does not contain the image-related *.import files
then the plugin fails to load the first time project is opened.

See here for "official" Godot .gitignore file: https://github.com/github/gitignore/blob/master/Godot.gitignore

The error on opening is (in a dialog box):

Unable to load addon script from path: 'res://addons/godot-camera-plugin.funabab/plugin.gd' There seems to be an error in the code, please check the syntax.

But the underlying error (in the Output console) is:

No loader found for resource: res://addons/godot-camera-plugin.funabab/icon_camera.png.
res://addons/godot-camera-plugin.funabab/camera_view.gd:6 - Parse Error: Can't preload resource at path: res://addons/godot-camera-plugin.funabab/icon_camera.png

For additional context, see: https://old.reddit.com/r/godot/comments/f4uhpk/i_get_stuck_with_android_plugin/

NOTE: This is part 1 of a 2 part fix.

If the plugin does not contain the image-related `*.import` files
then the plugin fails to load the first time project is opened.

See here for "official" Godot `.gitignore` file: <https://github.com/github/gitignore/blob/master/Godot.gitignore>

The error on opening is (in a dialog box):

    Unable to load addon script from path: 'res://addons/godot-camera-plugin.funabab/plugin.gd' There seems to be an error in the code, please check the syntax.

But the underlying error (in the Output console) is:

    No loader found for resource: res://addons/godot-camera-plugin.funabab/icon_camera.png.
    res://addons/godot-camera-plugin.funabab/camera_view.gd:6 - Parse Error: Can't preload resource at path: res://addons/godot-camera-plugin.funabab/icon_camera.png

For additional context, see: <https://old.reddit.com/r/godot/comments/f4uhpk/i_get_stuck_with_android_plugin/>
NOTE: This is part 2 of a 2 part fix.

If the plugin does not contain the image-related `*.import` files
then the plugin fails to load the first time project is opened.

See here for "official" Godot `.gitignore` file: <https://github.com/github/gitignore/blob/master/Godot.gitignore>

The error on opening is (in a dialog box):

    Unable to load addon script from path: 'res://addons/godot-camera-plugin.funabab/plugin.gd' There seems to be an error in the code, please check the syntax.

But the underlying error (in the Output console) is:

    No loader found for resource: res://addons/godot-camera-plugin.funabab/icon_camera.png.
    res://addons/godot-camera-plugin.funabab/camera_view.gd:6 - Parse Error: Can't preload resource at path: res://addons/godot-camera-plugin.funabab/icon_camera.png

For additional context, see: <https://old.reddit.com/r/godot/comments/f4uhpk/i_get_stuck_with_android_plugin/>
@follower follower changed the title Remove incorrect *.import from .gitignore as it breaks plugin. Remove incorrect *.import from .gitignore as it breaks plugin & add missing *.import files Feb 18, 2020
@follower
Copy link
Author

Actually, no, the fix isn't this easy--because the files in .import don't seem to exist at the time the plugin is loaded:

 scene/resources/texture.cpp:502 - Condition "!f" is true. Returned: ERR_CANT_OPEN
 Failed loading resource: res://.import/icon_camera.png-b2668087f7e7255e71cd8888d15ae040.stex.
 Failed loading resource: res://addons/godot-camera-plugin.funabab/icon_camera.png.
 res://addons/godot-camera-plugin.funabab/camera_view.gd:6 - Parse Error: Can't preload resource at path: res://addons/godot-camera-plugin.funabab/icon_camera.png
 modules/gdscript/gdscript.cpp:576 - Method failed. Returning: ERR_PARSE_ERROR
 res://addons/godot-camera-plugin.funabab/plugin.gd:8 - Parse Error: Couldn't fully preload the script, possible cyclic reference or compilation error. Use "load()" instead if a cyclic reference is intended.
 modules/gdscript/gdscript.cpp:576 - Method failed. Returning: ERR_PARSE_ERROR

This was testing via a fresh checkout of my fork. :/

It may be a Godot plugin issue...

@follower
Copy link
Author

So, even with the following patch to use load() rather than preload() and var rather than const in one place:

diff --git a/addons/godot-camera-plugin.funabab/camera_view.gd b/addons/godot-camera-plugin.funabab/camera_view.gd
index 3f0c640..88bf956 100644
--- a/addons/godot-camera-plugin.funabab/camera_view.gd
+++ b/addons/godot-camera-plugin.funabab/camera_view.gd
@@ -3,7 +3,7 @@ extends Control
 
 const CameraViewNativeBridge = preload("camera_view_native_bridge.gd").CameraViewNativeBridge;
 const ERROR_FATAL = 1;
-const ICON_CAMERA = preload("icon_camera.png");
+var ICON_CAMERA = load("res://addons/godot-camera-plugin.funabab/icon_camera.png");
 const COLOR_BG = Color.black;
 
 enum ERROR {
diff --git a/addons/godot-camera-plugin.funabab/plugin.gd b/addons/godot-camera-plugin.funabab/plugin.gd
index f93656b..4352a19 100644
--- a/addons/godot-camera-plugin.funabab/plugin.gd
+++ b/addons/godot-camera-plugin.funabab/plugin.gd
@@ -5,7 +5,7 @@ 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"));
+       add_custom_type(CUSTOM_NODE_NAME, "Control", preload("camera_view.gd"), load("res://addons/godot-camera-plugin.funabab/icon_node.png"));
        pass
 
 func _exit_tree():

An error is still displayed on opening for the "first" time (i.e. after deleting .import directory):

 scene/resources/texture.cpp:502 - Condition "!f" is true. Returned: ERR_CANT_OPEN
 Failed loading resource: res://.import/icon_node.png-30f8f9efd25c6739f8122fe2bfd0aae8.stex.
 Failed loading resource: res://addons/godot-camera-plugin.funabab/icon_node.png.

No pop-up appears in this scenario & the plugin maybe still seems to "work" but the Node tree displays a generic icon.

@follower
Copy link
Author

Yeah, this seems to be an engine issue: godotengine/godot#17483

Particularly relevant comment: godotengine/godot#17483 (comment)

@follower
Copy link
Author

Okay, for the record, with this patch (and no existing .import) the plugin opens successfully (but does give a yellow warning):

diff --git a/addons/godot-camera-plugin.funabab/camera_view.gd b/addons/godot-camera-plugin.funabab/camera_view.gd
index 3f0c640..88bf956 100644
--- a/addons/godot-camera-plugin.funabab/camera_view.gd
+++ b/addons/godot-camera-plugin.funabab/camera_view.gd
@@ -3,7 +3,7 @@ extends Control
 
 const CameraViewNativeBridge = preload("camera_view_native_bridge.gd").CameraViewNativeBridge;
 const ERROR_FATAL = 1;
-const ICON_CAMERA = preload("icon_camera.png");
+var ICON_CAMERA = load("res://addons/godot-camera-plugin.funabab/icon_camera.png");
 const COLOR_BG = Color.black;
 
 enum ERROR {
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():

The warning is:

 core/image.cpp:1882 - Loaded resource as image file, this will not work on export: 'res://addons/godot-camera-plugin.funabab/icon_node.png'. Instead, import the image file as an Image resource and load it normally as a resource.

Given the node icon is only used in the editor I assume it's not going to be an issue on export? (lol)

Note: I haven't tested an export.

follower added a commit to follower/godot-camera-plugin-demo that referenced this pull request Feb 18, 2020
@follower
Copy link
Author

There's a simpler workaround that has some trade-offs but for now here's the diff: master...follower:workaround-plugin-init-png-issue-alt

In brief, change from load()/preload() to ResourceLoader.load() which returns a null object but not an error on failure:

add_custom_type(CUSTOM_NODE_NAME, "Control", preload("camera_view.gd"), ResourceLoader.load("res://addons/godot-camera-plugin.funabab/icon_node.png"))

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

Successfully merging this pull request may close these issues.

None yet

1 participant