diff options
author | HampusM <hampus@hampusmat.com> | 2024-05-19 13:12:59 +0200 |
---|---|---|
committer | HampusM <hampus@hampusmat.com> | 2024-05-19 13:12:59 +0200 |
commit | 355a19e630de61397bf70b69b7ab2356318be2b8 (patch) | |
tree | 71774709c0407375850c54fe59feb542e05fdb51 /glfw/src/init.rs | |
parent | 3884f9bdd775afd3a40503286eb5d06ef72eeb1a (diff) |
fix(glfw): check major version of GLFW shared library
Diffstat (limited to 'glfw/src/init.rs')
-rw-r--r-- | glfw/src/init.rs | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/glfw/src/init.rs b/glfw/src/init.rs index b42bb52..df5a989 100644 --- a/glfw/src/init.rs +++ b/glfw/src/init.rs @@ -1,6 +1,12 @@ +use std::ffi::c_int; +use std::ptr::null_mut; + use crate::util::is_main_thread; use crate::{get_glfw_error, Error}; +/// GLFW 3.x.x is supported +static SUPPORTED_GLFW_VERSION_MAJOR: c_int = 3; + /// Initializes GLFW and returns a initialization token. /// /// # Errors @@ -13,6 +19,14 @@ pub fn initialize() -> Result<Glfw, Error> return Err(Error::NotInMainThread); } + let mut major: c_int = 0; + + unsafe { crate::ffi::glfwGetVersion(&mut major, null_mut(), null_mut()) }; + + if major != SUPPORTED_GLFW_VERSION_MAJOR { + return Err(Error::UnsupportedVersion); + } + // SAFETY: The current thread is the main thread let success = unsafe { crate::ffi::glfwInit() }; |