-
Notifications
You must be signed in to change notification settings - Fork 11
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
Dropping Instance in the wrong order causes a crash on exit #35
Comments
This is a really good find! I looked at the I can think of 2-3 possible solutions offhand:
I think I have a proof-of-concept for the first option, so I'll try to put up a PR making that change. In the meantime at least it sounds like you can enforce drop order manually to avoid the crash? |
I'm not sure if it's actually explicitly defined as such (it seems like the kind of thing that would be, but I can't find it immediately), but in practice, local variables are dropped in reverse declaration order if they're not otherwise linked. That means you can just declare the instance before any of the targets, and then they'll all be dropped first. |
I think this would be the relevant reference page: https://doc.rust-lang.org/reference/destructors.html#drop-scopes You can also explicitly
Very cool! I had previously started attempting to write some Bevy plugins with this toolchain at https://github.com/ian-h-chamberlain/bevy_3ds/ but I never got around to any graphics stuff because I wanted to flesh out the I'm definitely interested in making Bevy a use case for this toolchain, so I'll be curious to hear about your progress integrating |
I think that's the right reference page, but I couldn't quite parse out whether it explicitly defines the order for local variables defined in the same scope. It's not hugely important, either way. We've essentially been working on the idea that we need to have graphics working before we handle anything else, so most of our focus has been going towards getting |
Thanks for the reminder — I had originally kept it as a private repo while I was hacking on it and only made it public after it seemed relevant to your efforts here. I've updated the repo to reflect its dual MIT/Apache-2.0 license, which seems like the most obvious choice given the rest of the Bevy ecosystem and this repo.
Definitely! I had been putting off some of these kinds of "basic" milestones as I tried to cover a lot of the In case you hadn't seen it and find it useful, #20 also includes another use case of rendering an actual mesh, which would probably make a good example too, but I hadn't got around to porting it to safe APIs yet. |
Yeah, I saw that a little while ago. Unfortunately, the main bit of rendering a model it doesn't touch, textures, is the bit I'm having difficulty with. I've successfully got a shape with a texture, but I find myself hopelessly lost trying to understand how the texture pipeline is supposed to work and I had to go a fair bit against my understanding of how it should work in order to get two faces with two different textures. PXL_20231223_094143210.mp4(Sorry for the terrible recording quality. I should have turned down my screen brightness first.) |
My friend figured it out, and in retrospect it's sort of obvious - textures have to be alive until they're drawn, and if they're freed before the end of the frame, strange things happen. TexEnvs still don't work how I think they do, but at least I can draw more than one texture at a time now. |
I've opened a new issue for the texenv thing, since that feels like something we might be able to encode into a safe Rust API (and we should if possible!), but let's keep this issue for tracking the render target stuff. For now, I think I'm inclined to try the |
I don't mind either way - whatever is nice to implement works for me. |
Yeah in hindsight I suppose that makes sense, since obviously the render code needs a reference to the program in order to use it... maybe it would be safer for Mind filing a new issue for this? These are the kinds of things that I think will really become the core of this library so I definitely want to spend some time designing it and coming up with an API that is as safe as possible while still being ergonomic. |
Done (#37) |
Hello @Jhynjhiruu, could you please share the source code of your textured square? I'm REALLY struggling to draw a simple image to the screen using the GPU. |
Hi there,
I've had a strange crash in my project for the past while, in which the program crashes while dropping the
Target
s for the top screen. I wasn't able to figure out exactly what's going wrong, until I noticed the difference between my program and the exampletriangle.rs
- my code was creating theInstance
object after theTarget
s, andtriangle.rs
was creating it before. Given what I know about aTarget
being bound to anInstance
, this makes a weird kind of sense - initialising theTarget
before theInstance
means that Rust will drop theInstance
first, and the instance callsC3D_Fini
when it's dropped, which presumably does something weird. (The crash itself is in the call tofree
within the C code, so presumably this also manifests using the C toolchain, though I didn't test that.)I was able to fix the crash pretty simply, by changing the
Instance
to be initialised first. Is there a better fix? Either unlinking the boundTarget
on drop somehow, or something fancy with lifetimes to ensure that theInstance
must outlive theTarget
attached to it?(For a simple repro of the crash, move line 61 of
triangle.rs
to line 83 (other places may also work), then build and run it on a real 3DS. Citra doesn't care about the crash, since it's on exit, but on a real 3DS, it means exiting to the Homebrew Menu or the HOME Menu isn't possible, which sucks a lot for testing.)The text was updated successfully, but these errors were encountered: