188 doesn't actually fix the core issue, it just papers over it; UB still occurs while zero initializing a type that disallows zero initialization. I believe this version fixes the UB. It performs no zero initialization, instead using std::ptr::read to get a copy, perform the function that consumes it, then write back the result if it succeeded, or the ctx from the error if it failed.
Edit:
I also try to catch panics in make_current and abort since there's not much I can do there. I feel like ctx really should just be an Option.
188 doesn't actually fix the core issue, it just papers over it; UB still occurs while zero initializing a type that disallows zero initialization. I believe this version fixes the UB. It performs no zero initialization, instead using
std::ptr::read
to get a copy, perform the function that consumes it, then write back the result if it succeeded, or thectx
from the error if it failed.Edit: I also try to catch panics in
make_current
and abort since there's not much I can do there. I feel likectx
really should just be anOption
.