From 6439a3779b664a04689b8411360eed79da0ee637 Mon Sep 17 00:00:00 2001 From: Kaito Udagawa Date: Sat, 13 Jan 2024 10:10:52 +0900 Subject: [PATCH 1/8] Fix uninitialized string bug --- src/FilterData.h | 4 ++-- src/ort-utils/ort-session-utils.cpp | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/FilterData.h b/src/FilterData.h index a8e22e3b..6e2d0cae 100644 --- a/src/FilterData.h +++ b/src/FilterData.h @@ -30,9 +30,9 @@ struct filter_data : public ORTModelData { std::mutex outputLock; #if _WIN32 - const wchar_t *modelFilepath = nullptr; + std::wstring modelFilepath; #else - const char *modelFilepath = nullptr; + std::string modelFilepath; #endif }; diff --git a/src/ort-utils/ort-session-utils.cpp b/src/ort-utils/ort-session-utils.cpp index fd83aa39..6f1fb9c8 100644 --- a/src/ort-utils/ort-session-utils.cpp +++ b/src/ort-utils/ort-session-utils.cpp @@ -57,9 +57,9 @@ int createOrtSession(filter_data *tf) std::wstring modelFilepath_ws(modelFilepath_s.size(), L' '); std::copy(modelFilepath_s.begin(), modelFilepath_s.end(), modelFilepath_ws.begin()); - tf->modelFilepath = modelFilepath_ws.c_str(); + tf->modelFilepath = modelFilepath_ws; #else - tf->modelFilepath = modelFilepath_s.c_str(); + tf->modelFilepath = modelFilepath_s; #endif try { @@ -92,7 +92,7 @@ int createOrtSession(filter_data *tf) sessionOptions, coreml_flags)); } #endif - tf->session.reset(new Ort::Session(*tf->env, tf->modelFilepath, + tf->session.reset(new Ort::Session(*tf->env, tf->modelFilepath.c_str(), sessionOptions)); } catch (const std::exception &e) { obs_log(LOG_ERROR, "%s", e.what()); From 47660df25d367a9859c55db30ebf2c9ee8f8ed5b Mon Sep 17 00:00:00 2001 From: Kaito Udagawa Date: Sat, 13 Jan 2024 10:21:02 +0900 Subject: [PATCH 2/8] Update background-filter.cpp --- src/background-filter.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/background-filter.cpp b/src/background-filter.cpp index 873981fc..3c59d3cb 100644 --- a/src/background-filter.cpp +++ b/src/background-filter.cpp @@ -367,9 +367,9 @@ void background_filter_update(void *data, obs_data_t *settings) obs_log(LOG_INFO, " Blur Focus Depth: %f", tf->blurFocusDepth); obs_log(LOG_INFO, " Disabled: %s", tf->isDisabled ? "true" : "false"); #ifdef _WIN32 - obs_log(LOG_INFO, " Model file path: %S", tf->modelFilepath); + obs_log(LOG_INFO, " Model file path: %S", tf->modelFilepath.c_str()); #else - obs_log(LOG_INFO, " Model file path: %s", tf->modelFilepath); + obs_log(LOG_INFO, " Model file path: %s", tf->modelFilepath.c_str()); #endif } From 8f87d462b0d90752e69af9de06dba8fa5503ecf3 Mon Sep 17 00:00:00 2001 From: Kaito Udagawa Date: Sat, 13 Jan 2024 12:15:03 +0900 Subject: [PATCH 3/8] Update ort-session-utils.cpp --- src/ort-utils/ort-session-utils.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/ort-utils/ort-session-utils.cpp b/src/ort-utils/ort-session-utils.cpp index 6f1fb9c8..d9adb891 100644 --- a/src/ort-utils/ort-session-utils.cpp +++ b/src/ort-utils/ort-session-utils.cpp @@ -92,8 +92,8 @@ int createOrtSession(filter_data *tf) sessionOptions, coreml_flags)); } #endif - tf->session.reset(new Ort::Session(*tf->env, tf->modelFilepath.c_str(), - sessionOptions)); + tf->session.reset(new Ort::Session( + *tf->env, tf->modelFilepath.c_str(), sessionOptions)); } catch (const std::exception &e) { obs_log(LOG_ERROR, "%s", e.what()); return OBS_BGREMOVAL_ORT_SESSION_ERROR_STARTUP; From 28dc8f59a4329d6dcc50319d803ba3502d632576 Mon Sep 17 00:00:00 2001 From: Kaito Udagawa Date: Sat, 13 Jan 2024 14:15:33 +0900 Subject: [PATCH 4/8] Update ort-session-utils.cpp --- src/ort-utils/ort-session-utils.cpp | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/ort-utils/ort-session-utils.cpp b/src/ort-utils/ort-session-utils.cpp index d9adb891..823bdfdb 100644 --- a/src/ort-utils/ort-session-utils.cpp +++ b/src/ort-utils/ort-session-utils.cpp @@ -13,6 +13,7 @@ #ifdef _WIN32 #include #include +#include #endif // _WIN32 #include @@ -51,17 +52,18 @@ int createOrtSession(filter_data *tf) } std::string modelFilepath_s(modelFilepath_rawPtr); - bfree(modelFilepath_rawPtr); #if _WIN32 - std::wstring modelFilepath_ws(modelFilepath_s.size(), L' '); - std::copy(modelFilepath_s.begin(), modelFilepath_s.end(), - modelFilepath_ws.begin()); - tf->modelFilepath = modelFilepath_ws; + int outLength = MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, modelFilepath_rawPtr, -1, nullptr, 0); + wchar_t outWchars[outLength]: + MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, modelFilepath_rawPtr, -1, outWchars, outLength); + tf->modelFilepath = std::wstring(outWchars, outLength); #else - tf->modelFilepath = modelFilepath_s; + tf->modelFilepath = std::string(modelFilepath_rawPtr); #endif + bfree(modelFilepath_rawPtr); + try { #if defined(__linux__) && defined(__x86_64__) && \ !defined(DISABLE_ONNXRUNTIME_GPU) From 588986bda3bb7219d2c38d6db4f57642ec6d2fb0 Mon Sep 17 00:00:00 2001 From: Kaito Udagawa Date: Sat, 13 Jan 2024 14:16:40 +0900 Subject: [PATCH 5/8] Update ort-session-utils.cpp --- src/ort-utils/ort-session-utils.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/ort-utils/ort-session-utils.cpp b/src/ort-utils/ort-session-utils.cpp index 823bdfdb..4cb6be7f 100644 --- a/src/ort-utils/ort-session-utils.cpp +++ b/src/ort-utils/ort-session-utils.cpp @@ -54,9 +54,11 @@ int createOrtSession(filter_data *tf) std::string modelFilepath_s(modelFilepath_rawPtr); #if _WIN32 - int outLength = MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, modelFilepath_rawPtr, -1, nullptr, 0); - wchar_t outWchars[outLength]: - MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, modelFilepath_rawPtr, -1, outWchars, outLength); + int outLength = MultiByteToWideChar( + CP_ACP, MB_PRECOMPOSED, modelFilepath_rawPtr, -1, nullptr, 0); + wchar_t outWchars[outLength]; + MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, modelFilepath_rawPtr, -1, + outWchars, outLength); tf->modelFilepath = std::wstring(outWchars, outLength); #else tf->modelFilepath = std::string(modelFilepath_rawPtr); From 225a854ec7c56a3bd2852275821e356282c72bba Mon Sep 17 00:00:00 2001 From: Kaito Udagawa Date: Sat, 13 Jan 2024 14:22:04 +0900 Subject: [PATCH 6/8] Update ort-session-utils.cpp --- src/ort-utils/ort-session-utils.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ort-utils/ort-session-utils.cpp b/src/ort-utils/ort-session-utils.cpp index 4cb6be7f..bd509ab4 100644 --- a/src/ort-utils/ort-session-utils.cpp +++ b/src/ort-utils/ort-session-utils.cpp @@ -59,7 +59,7 @@ int createOrtSession(filter_data *tf) wchar_t outWchars[outLength]; MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, modelFilepath_rawPtr, -1, outWchars, outLength); - tf->modelFilepath = std::wstring(outWchars, outLength); + tf->modelFilepath = std::wstring(outWchars, (size_t)outLength); #else tf->modelFilepath = std::string(modelFilepath_rawPtr); #endif From 66a6c5346b1a6273423bbeabb8c08904ae0832b8 Mon Sep 17 00:00:00 2001 From: Kaito Udagawa Date: Sat, 13 Jan 2024 14:38:52 +0900 Subject: [PATCH 7/8] Update ort-session-utils.cpp --- src/ort-utils/ort-session-utils.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/ort-utils/ort-session-utils.cpp b/src/ort-utils/ort-session-utils.cpp index bd509ab4..0bd7dc4d 100644 --- a/src/ort-utils/ort-session-utils.cpp +++ b/src/ort-utils/ort-session-utils.cpp @@ -56,10 +56,10 @@ int createOrtSession(filter_data *tf) #if _WIN32 int outLength = MultiByteToWideChar( CP_ACP, MB_PRECOMPOSED, modelFilepath_rawPtr, -1, nullptr, 0); - wchar_t outWchars[outLength]; + std::vector outWchars(outLength); MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, modelFilepath_rawPtr, -1, - outWchars, outLength); - tf->modelFilepath = std::wstring(outWchars, (size_t)outLength); + outWchars.data(), outLength); + tf->modelFilepath = std::wstring(outWchars.begin(), outWchars.end()); #else tf->modelFilepath = std::string(modelFilepath_rawPtr); #endif From a0d617bb70b65c597423a595185b6ee646e14d9c Mon Sep 17 00:00:00 2001 From: Kaito Udagawa Date: Sat, 13 Jan 2024 14:47:30 +0900 Subject: [PATCH 8/8] Update ort-session-utils.cpp --- src/ort-utils/ort-session-utils.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/ort-utils/ort-session-utils.cpp b/src/ort-utils/ort-session-utils.cpp index 0bd7dc4d..795e945e 100644 --- a/src/ort-utils/ort-session-utils.cpp +++ b/src/ort-utils/ort-session-utils.cpp @@ -56,10 +56,9 @@ int createOrtSession(filter_data *tf) #if _WIN32 int outLength = MultiByteToWideChar( CP_ACP, MB_PRECOMPOSED, modelFilepath_rawPtr, -1, nullptr, 0); - std::vector outWchars(outLength); + tf->modelFilepath = std::wstring(outLength, L'\0'); MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, modelFilepath_rawPtr, -1, - outWchars.data(), outLength); - tf->modelFilepath = std::wstring(outWchars.begin(), outWchars.end()); + tf->modelFilepath.data(), outLength); #else tf->modelFilepath = std::string(modelFilepath_rawPtr); #endif