Skip to content

Commit

Permalink
Move obs_module_set_pointer back in lib.rs
Browse files Browse the repository at this point in the history
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 LiveSplit#41
  • Loading branch information
Refragg committed Sep 20, 2023
1 parent c3c6e45 commit d5cac12
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 22 deletions.
15 changes: 4 additions & 11 deletions src/auto_splitters.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<obs_module_t> = AtomicPtr::new(ptr::null_mut());

pub fn get_module_config_path() -> &'static PathBuf {
static OBS_MODULE_CONFIG_PATH: OnceLock<PathBuf> = OnceLock::new();

Expand All @@ -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() {
Expand All @@ -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<List> = OnceLock::new();

pub fn get_list() -> &'static List {
Expand Down
32 changes: 21 additions & 11 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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,
Expand Down Expand Up @@ -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 {
Expand All @@ -71,6 +72,15 @@ macro_rules! cstr {
#[cfg(feature = "auto-splitting")]
mod auto_splitters;

static OBS_MODULE_POINTER: AtomicPtr<obs_module_t> = 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
Expand Down

0 comments on commit d5cac12

Please sign in to comment.