OpenToonz - An open-source full-featured 2D animation creation software
C
try fix lvcod64.dll crash
konero6e6f011d40be
diff --git a/toonz/sources/image/avi/tiio_avi.cpp b/toonz/sources/image/avi/tiio_avi.cppindex c53558a19..4f4aeb2a0 100644--- a/toonz/sources/image/avi/tiio_avi.cpp+++ b/toonz/sources/image/avi/tiio_avi.cpp@@ -970,7 +970,7 @@ TImageP TLevelReaderAvi::load(int frameIndex) {int TLevelReaderAvi::readFrameFromStream(void *bufferOut, DWORD &bufferSize,int frameIndex) const {assert(bufferOut && bufferSize > 0);- LONG bytesReaded = 0;+ LONG bytesReaded = 0;LONG samplesRead = 0;int rc = AVIStreamRead(m_videoStream, frameIndex, 1, bufferOut, bufferSize,@@ -1112,7 +1112,7 @@ LRESULT safe_ICCompressQuery(hic_t const &hic, BITMAPINFO *lpbiInput,Tiio::AviWriterProperties::AviWriterProperties() : m_codec("Codec") {if (m_defaultCodec.getRange().empty()) {- char descr[2048], name[2048];+ char descr[2048], name[2048], driver[2048];DWORD fccType = 0;ICINFO icinfo;BITMAPINFO inFmt;@@ -1125,6 +1125,12 @@ Tiio::AviWriterProperties::AviWriterProperties() : m_codec("Codec") {inFmt.bmiHeader.biHeight = 100;inFmt.bmiHeader.biPlanes = 1;inFmt.bmiHeader.biCompression = BI_RGB;++ // List of known problematic DLLs that should be skipped+ const std::vector<std::string> blockedDlls = {"msvfw32.dll", "lvcod64.dll",+ "ff_vfw.dll", "tsccvid64.dll",+ "hapcodec.dll"};+for (int bpp = 32; bpp >= 24; bpp -= 8) {inFmt.bmiHeader.biBitCount = bpp;for (int i = 0;; i++) {@@ -1133,33 +1139,56 @@ Tiio::AviWriterProperties::AviWriterProperties() : m_codec("Codec") {break;}+ WideChar2Char(icinfo.szDriver, driver, sizeof(driver));++ // Convert driver name to lowercase for case-insensitive comparison+ std::string driverStr(driver);+ std::transform(driverStr.begin(), driverStr.end(), driverStr.begin(),+ ::tolower);++ // Skip blacklisted DLLs+ bool isBlocked =+ std::any_of(blockedDlls.begin(), blockedDlls.end(),+ [&](const std::string &blocked) {+ return driverStr.find(blocked) != std::string::npos;+ });++ if (isBlocked) {+ continue; // Skip this codec+ }+auto const hic =safe_ICOpen(icinfo.fccType, icinfo.fccHandler, ICMODE_QUERY);if (!hic) {- break;+ continue;}// Find out the compressor nameif (safe_ICGetInfo(hic, &icinfo, sizeof(ICINFO)) == 0) {- break;+ continue;}WideChar2Char(icinfo.szDescription, descr, sizeof(descr));WideChar2Char(icinfo.szName, name, sizeof(name));- if ((strstr(name, "IYUV") != 0) ||- ((strstr(name, "IR32") != 0) && (bpp == 24))) {++ // Skip certain codecs that are known to cause issues+ if (strstr(name, "IYUV") != nullptr ||+ (strstr(name, "IR32") != nullptr && bpp == 24)) {continue;}+// Give up to load codecs once the blackmagic codec is found -// as it seems to cause crash for unknown reasons (issue #138)- if (strstr(descr, "Blackmagic") != 0) break;+ if (strstr(descr, "Blackmagic") != nullptr) {+ break;+ }- std::string compressorName;- compressorName = std::string(name) + " '" + std::to_string(bpp) + "' " +- std::string(descr);+ std::string compressorName = std::string(name) + " '" ++ std::to_string(bpp) + "' " ++ std::string(descr);- // per il momento togliamo i codec indeo- if (std::string(compressorName).find("Indeo") != -1) {+ // Skip Indeo codecs, as they are obsolete and unreliable+ if (compressorName.find("Indeo") != std::string::npos) {continue;}@@ -1168,12 +1197,13 @@ Tiio::AviWriterProperties::AviWriterProperties() : m_codec("Codec") {}m_defaultCodec.addValue(::to_wstring(compressorName));- if (compressorName.find("inepak") != -1) {+ if (compressorName.find("inepak") != std::string::npos) {m_defaultCodec.setValue(::to_wstring(compressorName));}}}}+m_codec = m_defaultCodec;bind(m_codec);}diff --git a/toonz/sources/toonzlib/avicodecrestrictions.cpp b/toonz/sources/toonzlib/avicodecrestrictions.cppindex fb260d74d..00d2db3b0 100644--- a/toonz/sources/toonzlib/avicodecrestrictions.cpp+++ b/toonz/sources/toonzlib/avicodecrestrictions.cpp@@ -7,6 +7,12 @@namespace {+void WideChar2Char(LPCWSTR wideCharStr, char *str, int strBuffSize) {+ if (!wideCharStr || !str) return;+ WideCharToMultiByte(CP_ACP, 0, wideCharStr, -1, str, strBuffSize, nullptr,+ nullptr);+}+HIC getCodec(const std::wstring &codecName, int &bpp) {HIC hic = 0;ICINFO icinfo;@@ -205,7 +211,7 @@ QMap<std::wstring, bool> AviCodecRestrictions::getUsableCodecs(ICINFO icinfo;memset(&icinfo, 0, sizeof(ICINFO));- char descr[2048], name[2048];+ char descr[2048], name[2048], driver[2048];DWORD fccType = 0;BITMAPINFO inFmt;@@ -215,36 +221,63 @@ QMap<std::wstring, bool> AviCodecRestrictions::getUsableCodecs(inFmt.bmiHeader.biWidth = inFmt.bmiHeader.biHeight = 100;inFmt.bmiHeader.biPlanes = 1;inFmt.bmiHeader.biCompression = BI_RGB;++ // List of known DLLs that may cause crashes+ const std::vector<std::string> blockedDlls = {"msvfw32.dll", "lvcod64.dll",+ "ff_vfw.dll", "tsccvid64.dll",+ "hapcodec.dll"};+int bpp;- for (bpp = 32; (bpp >= 24); bpp -= 8) {- // find the codec.+ for (bpp = 32; bpp >= 24; bpp -= 8) {inFmt.bmiHeader.biBitCount = bpp;+for (int i = 0; ICInfo(fccType, i, &icinfo); i++) {+ WideChar2Char(icinfo.szDriver, driver, sizeof(driver));++ // Convert driver name to lowercase for case-insensitive comparison+ std::string driverStr =+ QString::fromStdString(std::string(driver)).toLower().toStdString();++ // Skip blacklisted DLLs before even trying to open the codec+ bool isBlocked =+ std::any_of(blockedDlls.begin(), blockedDlls.end(),+ [&](const std::string &blocked) {+ return driverStr.find(blocked) != std::string::npos;+ });++ if (isBlocked) {+ continue;+ }+hic = ICOpen(icinfo.fccType, icinfo.fccHandler, ICMODE_COMPRESS);+ if (!hic) {+ continue;+ }++ ICGetInfo(hic, &icinfo, sizeof(ICINFO));- ICGetInfo(hic, &icinfo, sizeof(ICINFO)); // Find out the compressor nameWideCharToMultiByte(CP_ACP, 0, icinfo.szDescription, -1, descr,sizeof(descr), 0, 0);WideCharToMultiByte(CP_ACP, 0, icinfo.szName, -1, name, sizeof(name), 0,0);- // Give up to load codecs once the blackmagic codec is found -- // as it seems to cause crash for unknown reasons (issue #138)- if (strstr(descr, "Blackmagic") != 0) break;- std::wstring compressorName;- compressorName =+ // Blackmagic codec can cause crashes, so stop processing if found+ if (strstr(descr, "Blackmagic") != nullptr) {+ ICClose(hic);+ break;+ }++ std::wstring compressorName =::to_wstring(std::string(name) + " '" + std::to_string(bpp) + "' " +std::string(descr));- if (hic) {- if (ICCompressQuery(hic, &inFmt, NULL) != ICERR_OK) {- ICClose(hic);- continue; // Skip this compressor if it can't handle the format.- }+ if (ICCompressQuery(hic, &inFmt, NULL) == ICERR_OK) {codecs[compressorName] = canWork(hic, resolution, bpp);- ICClose(hic);}++ ICClose(hic);}}+return codecs;}