From d5cac126a7a0aed33d868b070077697254fdcf8c Mon Sep 17 00:00:00 2001 From: Refrag Date: Wed, 20 Sep 2023 18:34:43 +0200 Subject: [PATCH] Move obs_module_set_pointer back in lib.rs The obs_module_set_pointer has been accidentally moved in the auto_splitter.rs file in a previous commit. This meant that it wasn't being built when the auto splitting feature was turned off. It turns out that it is actually essential for the obs module to register correctly, which means it wasn't working anymore when auto splitting was turned off. This patch moves it back to the main lib.rs file so that it is exported no matter the configuration we're in. I also added a comment to clarify what this is doing as it might not be very clear. This fixes #41 --- src/auto_splitters.rs | 15 ++++----------- src/lib.rs | 32 +++++++++++++++++++++----------- 2 files changed, 25 insertions(+), 22 deletions(-) diff --git a/src/auto_splitters.rs b/src/auto_splitters.rs index a19a040..c5d6f97 100644 --- a/src/auto_splitters.rs +++ b/src/auto_splitters.rs @@ -8,19 +8,17 @@ use std::{ ffi::CStr, fs, path::{Path, PathBuf}, - ptr, str, + str, sync::{ - atomic::{self, AtomicPtr}, + atomic::{self}, OnceLock, }, }; -use crate::{ffi::obs_module_get_config_path, ffi_types::obs_module_t}; +use crate::ffi::obs_module_get_config_path; const LIST_FILE_NAME: &str = "LiveSplit.AutoSplitters.xml"; -static OBS_MODULE_POINTER: AtomicPtr = AtomicPtr::new(ptr::null_mut()); - pub fn get_module_config_path() -> &'static PathBuf { static OBS_MODULE_CONFIG_PATH: OnceLock = OnceLock::new(); @@ -29,7 +27,7 @@ pub fn get_module_config_path() -> &'static PathBuf { unsafe { let config_path_ptr = obs_module_get_config_path( - OBS_MODULE_POINTER.load(atomic::Ordering::Relaxed), + crate::OBS_MODULE_POINTER.load(atomic::Ordering::Relaxed), cstr!(""), ); if let Ok(config_path) = CStr::from_ptr(config_path_ptr).to_str() { @@ -41,11 +39,6 @@ pub fn get_module_config_path() -> &'static PathBuf { }) } -#[no_mangle] -pub extern "C" fn obs_module_set_pointer(module: *mut obs_module_t) { - OBS_MODULE_POINTER.store(module, atomic::Ordering::Relaxed); -} - pub static LIST: OnceLock = OnceLock::new(); pub fn get_list() -> &'static List { diff --git a/src/lib.rs b/src/lib.rs index 6f163ef..cf886a9 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -9,7 +9,10 @@ use std::{ path::{Path, PathBuf}, process::Command, ptr, - sync::{Arc, Mutex, Weak}, + sync::{ + atomic::{self, AtomicPtr}, + Arc, Mutex, Weak, + }, }; mod ffi; @@ -22,12 +25,13 @@ use ffi::{ gs_texture_set_image, gs_texture_t, obs_data_get_bool, obs_data_get_int, obs_data_get_string, obs_data_set_default_bool, obs_data_set_default_int, obs_data_t, obs_enter_graphics, obs_get_base_effect, obs_hotkey_id, obs_hotkey_register_source, obs_hotkey_t, - obs_leave_graphics, obs_mouse_event, obs_properties_add_bool, obs_properties_add_button, - obs_properties_add_int, obs_properties_add_path, obs_properties_create, - obs_property_set_modified_callback2, obs_property_t, obs_register_source_s, obs_source_info, - obs_source_t, GS_DYNAMIC, GS_RGBA, LOG_WARNING, OBS_EFFECT_PREMULTIPLIED_ALPHA, - OBS_ICON_TYPE_GAME_CAPTURE, OBS_PATH_FILE, OBS_SOURCE_CONTROLLABLE_MEDIA, - OBS_SOURCE_CUSTOM_DRAW, OBS_SOURCE_INTERACTION, OBS_SOURCE_TYPE_INPUT, OBS_SOURCE_VIDEO, + obs_leave_graphics, obs_module_t, obs_mouse_event, obs_properties_add_bool, + obs_properties_add_button, obs_properties_add_int, obs_properties_add_path, + obs_properties_create, obs_property_set_modified_callback2, obs_property_t, + obs_register_source_s, obs_source_info, obs_source_t, GS_DYNAMIC, GS_RGBA, LOG_WARNING, + OBS_EFFECT_PREMULTIPLIED_ALPHA, OBS_ICON_TYPE_GAME_CAPTURE, OBS_PATH_FILE, + OBS_SOURCE_CONTROLLABLE_MEDIA, OBS_SOURCE_CUSTOM_DRAW, OBS_SOURCE_INTERACTION, + OBS_SOURCE_TYPE_INPUT, OBS_SOURCE_VIDEO, }; use ffi_types::{ obs_media_state, obs_properties_t, LOG_DEBUG, LOG_ERROR, LOG_INFO, OBS_MEDIA_STATE_ENDED, @@ -56,10 +60,7 @@ use { livesplit_core::auto_splitting, livesplit_core::auto_splitting::{SettingValue, UserSetting, UserSettingKind}, log::error, - std::{ - ffi::CString, - sync::atomic::{self, AtomicBool}, - }, + std::{ffi::CString, sync::atomic::AtomicBool}, }; macro_rules! cstr { @@ -71,6 +72,15 @@ macro_rules! cstr { #[cfg(feature = "auto-splitting")] mod auto_splitters; +static OBS_MODULE_POINTER: AtomicPtr = AtomicPtr::new(ptr::null_mut()); + +// This function is required for the OBS module registration to happen +// It is essentially like calling OBS_DECLARE_MODULE() in C +#[no_mangle] +pub extern "C" fn obs_module_set_pointer(module: *mut obs_module_t) { + OBS_MODULE_POINTER.store(module, atomic::Ordering::Relaxed); +} + #[no_mangle] pub extern "C" fn obs_module_ver() -> u32 { (26 << 24) | (1 << 16) | 1