vapoursynth: Reset locale after initializing

On Windows, Python changes the application's locale upon being called,
which will break wxwidgets, causing various assertion error dialogs or
even crashes (for example when interacting with any sort of float edit
control). Saving the locale and restoring it afterwards seems to be
the only really possible way to remedy this.
This commit is contained in:
arch1t3cht 2022-11-01 20:16:56 +01:00
parent 3583e57ddc
commit a3b131a312
2 changed files with 9 additions and 2 deletions

View file

@ -23,15 +23,17 @@
#include <boost/algorithm/string/replace.hpp>
int OpenScriptOrVideo(const VSSCRIPTAPI *api, VSScript *script, agi::fs::path const& filename, std::string default_script) {
int result;
if (agi::fs::HasExtension(filename, "py") || agi::fs::HasExtension(filename, "vpy")) {
return api->evaluateFile(script, filename.string().c_str());
result = api->evaluateFile(script, filename.string().c_str());
} else {
std::string fname = filename.string();
boost::replace_all(fname, "\\", "\\\\");
boost::replace_all(fname, "'", "\\'");
std::string vscript = "filename = '" + fname + "'\n" + default_script;
return api->evaluateBuffer(script, vscript.c_str(), "aegisub");
result = api->evaluateBuffer(script, vscript.c_str(), "aegisub");
}
return result;
}
#endif // WITH_VAPOURSYNTH

View file

@ -78,7 +78,12 @@ VapourSynthWrapper::VapourSynthWrapper() {
if (!getVSScriptAPI)
throw VapoursynthError("Failed to get address of getVSScriptAPI from " VSSCRIPT_SO);
// Python will set the program's locale to the user's default locale, which will break
// half of wxwidgets on some operating systems due to locale mismatches. There's not really anything
// we can do to fix it except for saving it and setting it back to its original value afterwards.
std::string oldlocale(setlocale(LC_ALL, NULL));
scriptapi = getVSScriptAPI(VSSCRIPT_API_VERSION);
setlocale(LC_ALL, oldlocale.c_str());
if (!scriptapi)
throw VapoursynthError("Failed to get Vapoursynth ScriptAPI");