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

Creating Detail Albedo texture in GDScript causes infinite textures being created. #56004

Open
Gyrth opened this issue Dec 16, 2021 · 3 comments
Milestone

Comments

@Gyrth
Copy link

Gyrth commented Dec 16, 2021

Godot version

v3.4-stable

System information

Manjaro Linux, GLES3, NVIDIA Geforce GTX 1060 495.44

Issue description

In my script I create a detail texture in the _ready function for bullet holes. It works flawlessly but I noticed the object id of the image object increase steadily. So this might be a memory leak, or needless swapping of textures in the engine.
Peek 2021-12-17 00-33

Steps to reproduce

  1. Open reproduction project.
  2. Run project.
  3. Click on the object in Material slot 0.
  4. Click the object in Detail Albedo.
  5. See the object id of the Image increase.

Minimal reproduction project

BugReport.zip

@Zylann
Copy link
Contributor

Zylann commented Dec 17, 2021

I think this is actually a side-effect of remote inspector, I have seen this in the past. It is trying to access image but for some reason I think it re-creates the object client-side just to provide it, but in reality it is not cached.
Similarly if you try to access image in script it might also create a new image each time because it does not actually store such object. Only the data inside is stored. In fact image is not even a documented property, I think it only exists because of serialization purposes.

You can also see some of that in master, the data is cached as a Ref<Image> only in some conditions in editor:

Ref<Image> RendererStorageRD::texture_2d_get(RID p_texture) const {
Texture *tex = texture_owner.get_or_null(p_texture);
ERR_FAIL_COND_V(!tex, Ref<Image>());
#ifdef TOOLS_ENABLED
if (tex->image_cache_2d.is_valid() && !tex->is_render_target) {
return tex->image_cache_2d;
}
#endif

Then in all the other cases, it gets the data probably from the graphics card or whatever cache if any, but because it gets it as raw bytes, it has to wrap it inside an Image object:

Vector<uint8_t> data = RD::get_singleton()->texture_get_data(tex->rd_texture, 0);
ERR_FAIL_COND_V(data.size() == 0, Ref<Image>());
Ref<Image> image;
image.instantiate();

Which explains why you may get a different instance of an Image object each time.

@Gyrth
Copy link
Author

Gyrth commented Dec 21, 2021

Thank you for checking it out.
So is this considered a bug worth fixing?

@Zylann
Copy link
Contributor

Zylann commented Dec 21, 2021

I'm not sure it is even a bug, it looks like it works as intended, as confusing as it looks. I wonder why it shows there in the first place.
Also I have a vague memory that this was raised before, but I can't find the issue if any.

Some other slightly related stuff from the past:
#18801 (comment)

@clayjohn clayjohn modified the milestones: 4.0, 4.x Feb 23, 2023
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

4 participants