PistonDevelopers / glfw-rs

GLFW3 bindings and idiomatic wrapper for Rust.
Apache License 2.0
645 stars 123 forks source link

Crate leaks unsafe functionality into safe rust!! #560

Closed GideonUng closed 7 months ago

GideonUng commented 8 months ago

i was writing my own wrapper and wondering how others solved wrapping monitors safely and i guess the answer is they simply dont...

there are several issues with just this screenshot where undefined behavior leaks into safe rust: Screenshot from 2024-01-30 01-56-39

glfwGetWindowMonitor() might return null. this is not checked glfwGetMonitorPos() it is not legal to supply null for the monitor paramter here (but might be given the function above)

and even further that monitor even saves a monitor pointer is illegal since glfw*Events() might invalidate those pointers making them point to trash memory. (after a monitor is disconnected)

and even further still there is no checking for the validity of the thread the monitor is created in. glfw is not thread safe for the most part and a monitor created on anything but the thread glfwInit() is called on is undefined behavior.

this is why i dont use any crates from crates.io. the state of rust is abysmal...

bohdloss commented 8 months ago

image Whoops! Looks like that was my fault. I'm going to fix this asap. Thanks for catching that!