obs-scripting: Fix script state variable being reset by tick callback
When loading a new Python script, the GIL might be released while importing the module, allowing the tick to run and change and reset the cur_python_script state variable. Use the busy_script variable to save and restore the value if not null.
This commit is contained in:
parent
dd06fe44ad
commit
0af8bdb350
13
deps/obs-scripting/obs-scripting-python.c
vendored
13
deps/obs-scripting/obs-scripting-python.c
vendored
@ -1514,6 +1514,11 @@ void obs_python_script_save(obs_script_t *s)
|
|||||||
static void python_tick(void *param, float seconds)
|
static void python_tick(void *param, float seconds)
|
||||||
{
|
{
|
||||||
struct obs_python_script *data;
|
struct obs_python_script *data;
|
||||||
|
/* When loading a new Python script, the GIL might be released while importing the module,
|
||||||
|
allowing the tick to run and change and reset the cur_python_script state variable. Use the
|
||||||
|
busy_script variable to save and restore the value if not null.
|
||||||
|
*/
|
||||||
|
struct obs_python_script *busy_script;
|
||||||
bool valid;
|
bool valid;
|
||||||
uint64_t ts = obs_get_video_frame_time();
|
uint64_t ts = obs_get_video_frame_time();
|
||||||
|
|
||||||
@ -1531,6 +1536,10 @@ static void python_tick(void *param, float seconds)
|
|||||||
|
|
||||||
pthread_mutex_lock(&tick_mutex);
|
pthread_mutex_lock(&tick_mutex);
|
||||||
data = first_tick_script;
|
data = first_tick_script;
|
||||||
|
|
||||||
|
if (cur_python_script)
|
||||||
|
busy_script = cur_python_script;
|
||||||
|
|
||||||
while (data) {
|
while (data) {
|
||||||
cur_python_script = data;
|
cur_python_script = data;
|
||||||
|
|
||||||
@ -1543,6 +1552,10 @@ static void python_tick(void *param, float seconds)
|
|||||||
}
|
}
|
||||||
|
|
||||||
cur_python_script = NULL;
|
cur_python_script = NULL;
|
||||||
|
if (busy_script) {
|
||||||
|
cur_python_script = busy_script;
|
||||||
|
busy_script = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
pthread_mutex_unlock(&tick_mutex);
|
pthread_mutex_unlock(&tick_mutex);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user