Skip to content

Commit c8c57ce

Browse files
committed
Prevent plugin from being loaded twice
1 parent 6e1ed58 commit c8c57ce

1 file changed

Lines changed: 18 additions & 0 deletions

File tree

module/advanced-scene-switcher-module.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,16 @@
11
#include <obs-module.h>
22
#include <obs-frontend-api.h>
3+
#include <stdlib.h>
4+
5+
#ifdef _WIN32
6+
#define ADVSS_SETENV(k, v) _putenv_s(k, v)
7+
#define ADVSS_UNSETENV(k) _putenv_s(k, "")
8+
#else
9+
#define ADVSS_SETENV(k, v) setenv(k, v, 1)
10+
#define ADVSS_UNSETENV(k) unsetenv(k)
11+
#endif
12+
13+
#define ADVSS_INSTANCE_ENV "ADVSS_INSTANCE_LOADED"
314

415
OBS_DECLARE_MODULE()
516
OBS_MODULE_USE_DEFAULT_LOCALE("advanced-scene-switcher", "en-US")
@@ -17,6 +28,12 @@ void obs_module_post_load(void)
1728

1829
bool obs_module_load(void)
1930
{
31+
if (getenv(ADVSS_INSTANCE_ENV)) {
32+
blog(LOG_WARNING,
33+
"[adv-ss] Another instance is already loaded - skipping.");
34+
return false;
35+
}
36+
ADVSS_SETENV(ADVSS_INSTANCE_ENV, "1");
2037
obs_frontend_push_ui_translation(obs_module_get_string);
2138
InitSceneSwitcher(obs_current_module(), obs_module_text);
2239
return true;
@@ -25,4 +42,5 @@ bool obs_module_load(void)
2542
void obs_module_unload(void)
2643
{
2744
FreeSceneSwitcher();
45+
ADVSS_UNSETENV(ADVSS_INSTANCE_ENV);
2846
}

0 commit comments

Comments
 (0)