deps/obs-scripting: Allow NULL script with script_log

(This commit also modifies the frontend-tools module)

Prevents a potential crash when script_log is called by a thread spawned
by a python library.
This commit is contained in:
jp9000 2018-01-31 01:46:16 -08:00
parent c87597f7d6
commit a2ae16e98c
3 changed files with 24 additions and 10 deletions

View File

@ -494,9 +494,14 @@ static void script_log(void *, obs_script_t *script, int log_level,
const char *message)
{
QString qmsg;
qmsg = QStringLiteral("[%1] %2").arg(
obs_script_get_file(script),
message);
if (script) {
qmsg = QStringLiteral("[%1] %2").arg(
obs_script_get_file(script),
message);
} else {
qmsg = QStringLiteral("[Unknown Script] %1").arg(message);
}
QMetaObject::invokeMethod(scriptLogWindow, "AddLogMsg",
Q_ARG(int, log_level),

View File

@ -28,14 +28,19 @@ void script_log_va(obs_script_t *script, int level, const char *format,
const char *lang = "(Unknown)";
size_t start_len;
switch (script->type) {
case OBS_SCRIPT_LANG_UNKNOWN: lang = "(Unknown language)"; break;
case OBS_SCRIPT_LANG_LUA: lang = "Lua"; break;
case OBS_SCRIPT_LANG_PYTHON: lang = "Python"; break;
if (script) {
switch (script->type) {
case OBS_SCRIPT_LANG_UNKNOWN: lang = "(Unknown language)"; break;
case OBS_SCRIPT_LANG_LUA: lang = "Lua"; break;
case OBS_SCRIPT_LANG_PYTHON: lang = "Python"; break;
}
start_len = snprintf(msg, sizeof(msg), "[%s: %s] ",
lang, script->file.array);
} else {
start_len = snprintf(msg, sizeof(msg), "[Unknown Script] ");
}
start_len = snprintf(msg, sizeof(msg), "[%s: %s] ",
lang, script->file.array);
vsnprintf(msg + start_len, sizeof(msg) - start_len, format, args);
if (callback)

View File

@ -1193,7 +1193,11 @@ static PyObject *py_script_log_internal(PyObject *self, PyObject *args,
while (endl) {
*endl = 0;
script_log(&cur_python_script->base, log_level, "%s", start);
if (cur_python_script)
script_log(&cur_python_script->base, log_level, "%s",
start);
else
script_log(NULL, log_level, "%s", start);
*endl = '\n';
start = endl + 1;