OpenToonz - An open-source full-featured 2D animation creation software
C
try fix dll crash again
konero30e7b4984d13
diff --git a/toonz/sources/common/tsystem/tsystem.cpp b/toonz/sources/common/tsystem/tsystem.cppindex a1fcdcb62..5adb30854 100644--- a/toonz/sources/common/tsystem/tsystem.cpp+++ b/toonz/sources/common/tsystem/tsystem.cpp@@ -1066,6 +1066,19 @@ bool TSystem::showDocument(const TFilePath &path) {#endif}+bool TSystem::isDLLBlackListed(QString dllFile) {+ QStringList dllBlackList = {"lvcod64.dll", "ff_vfw.dll", "tsccvid64.dll",+ "hapcodec.dll"};++ for (int x = 0; x < dllBlackList.count(); x++) {+ if (dllFile.contains(dllBlackList.at(x), Qt::CaseInsensitive)) {+ return true;+ }+ }++ return false;+}+#else#include <windows.h>diff --git a/toonz/sources/image/avi/tiio_avi.cpp b/toonz/sources/image/avi/tiio_avi.cppindex 4f4aeb2a0..9cf99eee4 100644--- a/toonz/sources/image/avi/tiio_avi.cpp+++ b/toonz/sources/image/avi/tiio_avi.cpp@@ -272,6 +272,14 @@ void TLevelWriterAvi::searchForCodec() {for (int bpp = 32; (bpp >= 24) && !found; bpp -= 8) {inFmt.bmiHeader.biBitCount = bpp;for (int i = 0; ICInfo(fccType, i, &icinfo); i++) {+ // Skip blacklisted DLLs+ char driver[2048];+ WideChar2Char(icinfo.szDriver, driver, sizeof(driver));+ if (TSystem::isDLLBlackListed(+ QString::fromStdString(std::string(driver)))) {+ continue;+ }+hic = ICOpen(icinfo.fccType, icinfo.fccHandler, ICMODE_COMPRESS);ICGetInfo(hic, &icinfo,@@ -720,7 +728,11 @@ TLevelReaderAvi::TLevelReaderAvi(const TFilePath &path)ICINFO icinfo;memset(&icinfo, 0, sizeof(ICINFO));ICInfo(ICTYPE_VIDEO, si.fccHandler, &icinfo);- m_hic = ICOpen(icinfo.fccType, icinfo.fccHandler, ICMODE_DECOMPRESS);++ char driver[2048];+ WideChar2Char(icinfo.szDriver, driver, sizeof(driver));+ if (!TSystem::isDLLBlackListed(driver))+ m_hic = ICOpen(icinfo.fccType, icinfo.fccHandler, ICMODE_DECOMPRESS);if (!m_hic) {m_hic = findCandidateDecompressor();if (!m_hic)@@ -786,6 +798,14 @@ HIC TLevelReaderAvi::findCandidateDecompressor() {info.dwSize = sizeof(ICINFO); // I don't think this is necessary, but just in case....+ // Skip blacklisted DLLs+ char driver[2048];+ WideChar2Char(info.szDriver, driver, sizeof(driver));+ if (TSystem::isDLLBlackListed(+ QString::fromStdString(std::string(driver)))) {+ continue;+ }+HIC hic = ICOpen(info.fccType, info.fccHandler, ICMODE_DECOMPRESS);if (!hic) continue;@@ -1112,7 +1132,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], driver[2048];+ char descr[2048], name[2048];DWORD fccType = 0;ICINFO icinfo;BITMAPINFO inFmt;@@ -1125,12 +1145,6 @@ 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++) {@@ -1139,56 +1153,41 @@ 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+ char driver[2048];+ WideChar2Char(icinfo.szDriver, driver, sizeof(driver));+ if (TSystem::isDLLBlackListed(+ QString::fromStdString(std::string(driver)))) {+ continue;}auto const hic =safe_ICOpen(icinfo.fccType, icinfo.fccHandler, ICMODE_QUERY);if (!hic) {- continue;+ break;}// Find out the compressor nameif (safe_ICGetInfo(hic, &icinfo, sizeof(ICINFO)) == 0) {- continue;+ break;}WideChar2Char(icinfo.szDescription, descr, sizeof(descr));WideChar2Char(icinfo.szName, name, sizeof(name));-- // Skip certain codecs that are known to cause issues- if (strstr(name, "IYUV") != nullptr ||- (strstr(name, "IR32") != nullptr && bpp == 24)) {+ if ((strstr(name, "IYUV") != 0) ||+ ((strstr(name, "IR32") != 0) && (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") != nullptr) {- break;- }+ if (strstr(descr, "Blackmagic") != 0) break;- std::string compressorName = std::string(name) + " '" +- std::to_string(bpp) + "' " +- std::string(descr);+ std::string compressorName;+ compressorName = std::string(name) + " '" + std::to_string(bpp) + "' " ++ std::string(descr);- // Skip Indeo codecs, as they are obsolete and unreliable- if (compressorName.find("Indeo") != std::string::npos) {+ // per il momento togliamo i codec indeo+ if (std::string(compressorName).find("Indeo") != -1) {continue;}@@ -1197,13 +1196,12 @@ Tiio::AviWriterProperties::AviWriterProperties() : m_codec("Codec") {}m_defaultCodec.addValue(::to_wstring(compressorName));- if (compressorName.find("inepak") != std::string::npos) {+ if (compressorName.find("inepak") != -1) {m_defaultCodec.setValue(::to_wstring(compressorName));}}}}-m_codec = m_defaultCodec;bind(m_codec);}diff --git a/toonz/sources/include/tsystem.h b/toonz/sources/include/tsystem.hindex ee7da07d9..2ca9583a9 100644--- a/toonz/sources/include/tsystem.h+++ b/toonz/sources/include/tsystem.h@@ -272,6 +272,9 @@ DVAPI QString getUserName();DVAPI QString getSystemValue(const TFilePath &name);DVAPI TFilePath getUniqueFile(QString field = "");#endif++DVAPI bool isDLLBlackListed(QString dllFile);+}//diff --git a/toonz/sources/toonzlib/avicodecrestrictions.cpp b/toonz/sources/toonzlib/avicodecrestrictions.cppindex 00d2db3b0..87a82bfb0 100644--- a/toonz/sources/toonzlib/avicodecrestrictions.cpp+++ b/toonz/sources/toonzlib/avicodecrestrictions.cpp@@ -2,15 +2,14 @@#include "avicodecrestrictions.h"#include "tconvert.h"+#include "tsystem.h"#include <windows.h>#include <vfw.h>namespace {void WideChar2Char(LPCWSTR wideCharStr, char *str, int strBuffSize) {- if (!wideCharStr || !str) return;- WideCharToMultiByte(CP_ACP, 0, wideCharStr, -1, str, strBuffSize, nullptr,- nullptr);+ WideCharToMultiByte(CP_ACP, 0, wideCharStr, -1, str, strBuffSize, 0, 0);}HIC getCodec(const std::wstring &codecName, int &bpp) {@@ -33,6 +32,14 @@ HIC getCodec(const std::wstring &codecName, int &bpp) {// find the codec.inFmt.bmiHeader.biBitCount = bpp;for (int i = 0; ICInfo(fccType, i, &icinfo); i++) {+ // Skip blacklisted DLLs+ char driver[2048];+ WideChar2Char(icinfo.szDriver, driver, sizeof(driver));+ if (TSystem::isDLLBlackListed(+ QString::fromStdString(std::string(driver)))) {+ continue;+ }+hic = ICOpen(icinfo.fccType, icinfo.fccHandler, ICMODE_COMPRESS);ICGetInfo(hic, &icinfo, sizeof(ICINFO)); // Find out the compressor name@@ -211,7 +218,7 @@ QMap<std::wstring, bool> AviCodecRestrictions::getUsableCodecs(ICINFO icinfo;memset(&icinfo, 0, sizeof(ICINFO));- char descr[2048], name[2048], driver[2048];+ char descr[2048], name[2048];DWORD fccType = 0;BITMAPINFO inFmt;@@ -221,63 +228,44 @@ 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) {+ for (bpp = 32; (bpp >= 24); bpp -= 8) {+ // find the codec.inFmt.bmiHeader.biBitCount = bpp;-for (int i = 0; ICInfo(fccType, i, &icinfo); i++) {+ // Skip blacklisted DLLs+ char driver[2048];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) {+ if (TSystem::isDLLBlackListed(+ QString::fromStdString(std::string(driver)))) {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;- // Blackmagic codec can cause crashes, so stop processing if found- if (strstr(descr, "Blackmagic") != nullptr) {- ICClose(hic);- break;- }-- std::wstring compressorName =+ std::wstring compressorName;+ compressorName =::to_wstring(std::string(name) + " '" + std::to_string(bpp) + "' " +std::string(descr));- if (ICCompressQuery(hic, &inFmt, NULL) == ICERR_OK) {+ if (hic) {+ if (ICCompressQuery(hic, &inFmt, NULL) != ICERR_OK) {+ ICClose(hic);+ continue; // Skip this compressor if it can't handle the format.+ }codecs[compressorName] = canWork(hic, resolution, bpp);+ ICClose(hic);}-- ICClose(hic);}}-return codecs;}