Closed crumblingstatue closed 8 years ago
Thanks. I prefer to change ths architecture of the library.
Can you post the minimal fail code here?
@andelf I edited the original post and added a test case.
:( The code runs ok under my macbook. sdl_* libs installed by homebrew.
Whether it runs fine for you specifically or not, the fact still remains that it triggers undefined behavior. It might run fine on some systems, it might crash on others. It might silently corrupt the program state on yet others. Undefined behavior must be eliminated, and it is forbidden in Rust to let safe code trigger it.
I'll try to tie the lifetime of a music to the lifetime of the sdl2_mixer context.
With that last pull request, this issue should be solved and can be closed
With that last pull request, this issue should be solved and can be closed
Alright, I can't reproduce this issue anymore (in fact, it even works without sdl::init()
or mix::init()
being called), so I'm going to close it.
If you call
mix::quit
before dropping aMusic
, dropping it will trigger undefined behavior and causes a segmentation fault on my system.This is unacceptable, as this can be caused by safe Rust code.
One solution is to just let the music leak if the library is not initialized anymore.
Another solution is to change the architecture of the library, as was done with rust-sdl2, to be able to tie the lifetime of a music to the lifetime of the sdl2_mixer context.
I haven't checked, but this issue most likely also applies to
Chunk
and maybe some other types that implementDrop
.Here is a minimal test case: