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

vita2d_free_texture crash when texture loaded with vita2d_load_PNG_file #28

Open
Cpasjuste opened this issue Sep 16, 2016 · 8 comments
Open

Comments

@Cpasjuste
Copy link

Hi,

it seems there's a bug when we try to free a texture loaded with vita2d_load_PNG_file, the device crash.

Here's an example :

vita2d_texture *tex =
vita2d_load_PNG_file("app0:data/test.png");

...draw...

vita2d_free_texture(tex); -> crash

@xerpi
Copy link
Owner

xerpi commented Sep 16, 2016

That's because the GPU is still using the texture while you are freeing it.

@Cpasjuste
Copy link
Author

Hum hum ok, so we have to use "vita2d_fini" before freeing them. It's not really convenient !

@xerpi
Copy link
Owner

xerpi commented Sep 16, 2016

After you free them, do you pretend to continue drawing other things or just exit the application?

@joel16
Copy link

joel16 commented Sep 22, 2016

Yeah I noticed this happened to me as well. I agree with @Cpasjuste, calling vit2d_fini before freeing isn't really convenient. Is there any way to overcome this?
And in my case, yes my program keeps drawing new textures @xerpi

@TheOfficialFloW
Copy link
Contributor

Wait vblank should do it.

@Dak0r
Copy link

Dak0r commented Sep 24, 2016

@Cpasjuste and @joel16
You don't need to call vita2d_fini, you just shouldn't free your texture while you are drawing.

You should have a look at START_DRAWING() and END_DTAWING in @TheOfficialFloW s VitaShell: https://github.com/henkaku/VitaShell/blob/master/main.h

Then you can take a look at photo.c, which uses free_texture in a way that works, without calling vita2d_fini: https://github.com/henkaku/VitaShell/blob/master/photo.c

You will notice it can be important where you call it:

....
while(1){
// you can free your textures here
START_DRAWING();
// you can't free your textures here, if you also draw them here
END_DRAWING();
// you can free your textures here
}
vita2d_fini();
....

When you have issues, try looking at how it's done in working examples like VitaShell

@xerpi
Copy link
Owner

xerpi commented Sep 24, 2016

@Cpasjuste if you want to continue using vita2d after freeing your images, you should call vita2d_wait_rendering_done(); before freeing them, this will block until the GPU has finished rendering.

thp added a commit to thp/libvita2d that referenced this issue Feb 10, 2019
thp added a commit to thp/libvita2d that referenced this issue Sep 17, 2022
@noword
Copy link

noword commented May 1, 2024

I encountered the same issue in my own project and found that the problem lies within the function _vita2d_create_empty_texture_format_advanced in vita2d_texture.c.

After vita2d_texture *texture = malloc(sizeof(*texture));, there was no memset performed, causing texture->gxm_rtgt to be non-zero.

This resulted in an error when vita2d_free_texture was called.

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

No branches or pull requests

6 participants