From 355a19e630de61397bf70b69b7ab2356318be2b8 Mon Sep 17 00:00:00 2001 From: HampusM Date: Sun, 19 May 2024 13:12:59 +0200 Subject: fix(glfw): check major version of GLFW shared library --- glfw/glfw.h | 4 ++++ glfw/src/init.rs | 14 ++++++++++++++ glfw/src/lib.rs | 3 +++ 3 files changed, 21 insertions(+) (limited to 'glfw') diff --git a/glfw/glfw.h b/glfw/glfw.h index f5fa479..7b435c0 100644 --- a/glfw/glfw.h +++ b/glfw/glfw.h @@ -1,2 +1,6 @@ #include +#if GLFW_VERSION_MAJOR != 3 +#error "Unsupported major version of GLFW. Must be 3" +#endif + 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 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() }; diff --git a/glfw/src/lib.rs b/glfw/src/lib.rs index 7d2f25c..f858766 100644 --- a/glfw/src/lib.rs +++ b/glfw/src/lib.rs @@ -22,6 +22,9 @@ pub enum Error #[error("An internal nul byte was found in the window title")] InternalNulByteInWindowTitle, + #[error("This version of GLFW is unsupported")] + UnsupportedVersion, + /// GLFW error. #[error("GLFW error {0} occured. {1}")] GlfwError(i32, String), -- cgit v1.2.3-18-g5258