macroquad
macroquad copied to clipboard
Improve safety of `get_quad_context`
This uses a thread local variable to ensure that the miniquad::Context
doesn't cross a thread boundary. It also enforces the mutable reference aliasing rules by nulling the pointer when it is borrowed and restoring it when the borrow ends
This uncovered one instance of UB in cargo test
due to an aliased mutable reference which has been fixed. There may be others which aren't covered by the test suite; they will now panic.
This is a breaking change because the type of get_internal_gl
has changed to include a guard object instead of an unbounded mutable reference; downstream users will need to adjust their code a bit (see the raw_miniquad
and particles
changes for an example of what this change may look like).