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

Image importing no longer working #63025

Closed
philomelus opened this issue Jul 15, 2022 · 9 comments · Fixed by #63127
Closed

Image importing no longer working #63025

philomelus opened this issue Jul 15, 2022 · 9 comments · Fixed by #63127

Comments

@philomelus
Copy link

Godot version

4.0a12

System information

Windows 10 Pro x64

Issue description

I cannot duplicate or load an imported image. After looking into it further, I attempted to run demo viewport/screen_capture, and it has a similar issue: When pushing the screen capture button, nothing happens. In the code, if you step through the callback for the button, it attempts to get a copy of the resource. The return in always null.
From my project, I am use load (even tried ResourceLoader.load) to load a PNG image that was imported as an Image (rather than a Texture2d as is the default), and when I call duplicate on the loaded image, I get nothing back.
Interestingly, I have an assert(image != null) before the duplicate call, and even though the debugger shows it as null, the assert never fails. The various calls made on the image also don't fail, but also don't appear to do anything.
I was using a local build of 4.x, but I also tried this with Alpha 12, with the same results.

Steps to reproduce

Load and run demo_project viewport/screen_capture. Attempt to capture screen by pushing screen capture button. Nothing happens.

Minimal reproduction project

demo_project/viewport/screen_capture

@Chaosus Chaosus added this to the 4.0 milestone Jul 15, 2022
@Chaosus Chaosus changed the title Image's no longer working Image importing no longer working Jul 15, 2022
@akien-mga
Copy link
Member

Try to delete the res://.godot/imported folder if it was generated before alpha 11.

@philomelus
Copy link
Author

philomelus commented Jul 15, 2022

I restarted from scratch with the 4.0a12 local build, so there weren't any existing imports. I was having other issues when I attempted to import my 3.5x local build version (which both GD and C# versions work fine with), and I couldn't figure out what I needed or not any longer (e.g. the font .tres are no longer needed, but they don't get removed on import, so I wasn't sure what to do).

Also, the import of the PNG worked. The first load appears in a Globals.gd that is auto-loaded, and the resource shows up there and in the debugger. When I attempt the duplicate() of the image, it does nothing. In fact, all attempts after the global load fail with it returning null, even if I do another load("res://image.png") with it. I actually did try that, specifically (that is, bypassing the global loaded one and loading to new variable from scratch; It doesn't work after the original globally loaded one does work).

@jeffgamedev
Copy link

jeffgamedev commented Jul 15, 2022

Hi, I've been able to recreate the issue in a minimum project. I have attached in a zip file.
image_load_issue_min_project.zip

@aaronfranke
Copy link
Member

I did a bisect and this was broken by #60739, specifically d290042 CC @KoBeWi

@aaronfranke
Copy link
Member

In the above test project, replacing these lines:

	new_texture = ImageTexture.new()
	new_texture.create_from_image(image)

with these lines:

	new_texture = ImageTexture.create_from_image(image)

causes the image to successfully load.

@KoBeWi
Copy link
Member

KoBeWi commented Jul 15, 2022

create_from_image() is now static, so you can't call it on an existing ImageTexture. Just skip ImageTexture.new().
The screen capture demo should be updated.

EDIT:
Also not sure what you mean by "I cannot duplicate or load an imported image". It works without problems.

@philomelus
Copy link
Author

philomelus commented Jul 16, 2022

I can confirm that this fixes the issues I'm having.

As for the cannot duplicate or load an imported image, I meant it literally:

@onready var i = load("image.png")

and later:

var d = i.duplicate()

d would still be null in the debugger, even though this never failed:

assert(d != null)

I saw there was bug about variables in the debugger not showing correctly, so maybe that is partially to blame.

Regardless, switching to static call fixes it in both my project and the demo code. Didn't occur to me that this was a documentation issue ...

@KoBeWi
Copy link
Member

KoBeWi commented Jul 16, 2022

Ah, now that you mention it, ImageTexture code examples weren't updated.

Also the most reliable way to test if something works is printing it. If the variable is null in the debugger then it's debugger bug xd

So to sum up, ImageTexture is working as intended and it just needs documentation fixup (also the demos using ImageTexture need to be updated too).

EDIT:
Actually the documentation was up-to-date, I probably checked a wrong version xd
Still, I made a PR to clarify it.

@philomelus
Copy link
Author

philomelus commented Jul 16, 2022

From my perspective, I was immediately attempting to create_from_image the result of the duplicate() call; Since the variable showed as null after the duplicate(), and the create_from_image was also not working, I really had no idea which was the real cause.

At least its an easy fix; Just wish it had occurred to me, so I could have prevented creating an issue for it (or maybe created an issue for the real cause, or just fixed it and pushed a pull request, or ...).

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

Successfully merging a pull request may close this issue.

6 participants