Skip to content

OpenToonz - An open-source full-featured 2D animation creation software

C

Fix crash opening PLI files

Anderson Pradoaa8a46d2362b
diff --git a/toonz/sources/common/timage/tlevel.cpp b/toonz/sources/common/timage/tlevel.cpp
index 9bc5f7e62..fffc0c868 100644
--- a/toonz/sources/common/timage/tlevel.cpp
+++ b/toonz/sources/common/timage/tlevel.cpp
@@ -11,7 +11,8 @@ TLevel::TLevel()
: TSmartObject(m_classCode)
, m_name("")
, m_table(new Table())
- , m_palette(0) {}
+ , m_palette(0)
+ , m_partialLoad(false) {}
//-------------------------------------------------
diff --git a/toonz/sources/common/tvectorimage/tcomputeregions.cpp b/toonz/sources/common/tvectorimage/tcomputeregions.cpp
index b0f71e84e..25bdd87b2 100644
--- a/toonz/sources/common/tvectorimage/tcomputeregions.cpp
+++ b/toonz/sources/common/tvectorimage/tcomputeregions.cpp
@@ -1944,6 +1944,7 @@ void autoclose(double factor, vector<VIStroke *> &s, int ii, int jj,
//-----------------------------------------------------------------------------
TPointD inline getTangent(const IntersectedStroke &item) {
+ if (!item.m_edge.m_s) return TPointD();
return (item.m_gettingOut ? 1 : -1) *
item.m_edge.m_s->getSpeed(item.m_edge.m_w0, item.m_gettingOut);
}
@@ -2485,6 +2486,7 @@ static TRegion *findRegion(VIList<Intersection> &intList, Intersection *p1,
}
} while (!p2->m_nextIntersection);
+ if (!p2->m_edge.m_s) continue;
nextp1 = p2->m_nextIntersection;
nextp2 = p2->m_nextStroke;
diff --git a/toonz/sources/image/pli/pli_io.cpp b/toonz/sources/image/pli/pli_io.cpp
index 2ea3b0e87..985391cba 100644
--- a/toonz/sources/image/pli/pli_io.cpp
+++ b/toonz/sources/image/pli/pli_io.cpp
@@ -184,6 +184,8 @@ void MyIfstream::open(const TFilePath &filename) {
m_fp = fopen(filename, "rb");
} catch (TException &) {
throw TImageException(filename, "File not found");
+ } catch (...) {
+ throw TImageException(filename, "Unhandled exception encountered");
}
}
@@ -740,6 +742,14 @@ void ParsedPliImp::loadInfo(bool readPlt, TPalette *&palette,
// palette = new TPalette();
// for (int i=0; i<256; i++)
// palette->getPage(0)->addStyle(TPixel::Black);
+
+ // File is missing frames! Load what we can.
+ // Last frame is likely an unusable image. Allow to load in case it was also
+ // the 1st frame, so we don't crash.
+ if (m_framesNumber > m_frameOffsInFile.size()) {
+ m_framesNumber = m_frameOffsInFile.size();
+ throw TException("Not all frames loaded.");
+ }
}
/*=====================================================================*/
@@ -825,7 +835,7 @@ ImageTag *ParsedPliImp::loadFrame(const TFrameId &frameNumber) {
while ((type = readTagHeader()) != PliTag::END_CNTRL) {
if (type == PliTag::IMAGE_BEGIN_GOBJ) {
m_iChan >> frame;
-
+
if (m_majorVersionNumber >= 150) {
TUINT32 suffixLength;
m_iChan >> suffixLength;
diff --git a/toonz/sources/image/pli/tiio_pli.cpp b/toonz/sources/image/pli/tiio_pli.cpp
index 4a44841b3..4391eaca6 100644
--- a/toonz/sources/image/pli/tiio_pli.cpp
+++ b/toonz/sources/image/pli/tiio_pli.cpp
@@ -811,7 +811,17 @@ TLevelP TLevelReaderPli::loadInfo() {
(majorVersionNumber != 5 || minorVersionNumber < 5))
return m_level;
TPalette *palette = 0;
- m_pli->loadInfo(m_readPalette, palette, m_contentHistory);
+ try {
+ m_pli->loadInfo(m_readPalette, palette, m_contentHistory);
+ } catch (TException &e) {
+ QString msg = QString::fromStdString(::to_string(e.getMessage()));
+ if (msg.contains("Not all frames loaded"))
+ m_level->setPartialLoad(true);
+ else
+ throw e;
+ } catch (...) {
+ throw;
+ }
if (palette) m_level->setPalette(palette);
for (int i = 0; i < m_pli->getFrameCount(); i++)
diff --git a/toonz/sources/include/tlevel.h b/toonz/sources/include/tlevel.h
index 08924c375..29b380745 100644
--- a/toonz/sources/include/tlevel.h
+++ b/toonz/sources/include/tlevel.h
@@ -30,6 +30,8 @@ private:
Table *m_table;
TPalette *m_palette;
+ bool m_partialLoad;
+
public:
TLevel();
~TLevel();
@@ -66,6 +68,9 @@ public:
TPalette *getPalette();
void setPalette(TPalette *);
+
+ void setPartialLoad(bool partial) { m_partialLoad = partial; }
+ bool isPartialLoad() { return m_partialLoad; }
};
//-------------------------------------------------------------------
diff --git a/toonz/sources/toonz/filebrowser.cpp b/toonz/sources/toonz/filebrowser.cpp
index a2a5e142b..a3d76cd87 100644
--- a/toonz/sources/toonz/filebrowser.cpp
+++ b/toonz/sources/toonz/filebrowser.cpp
@@ -886,7 +886,8 @@ item.m_validInfo = true;*/
//! calculated by using a dedicated thread and therefore cannot be simply
//! classified as *valid* or *invalid* infos...
void FileBrowser::readFrameCount(Item &item) {
- if (TFileType::isViewable(TFileType::getInfo(item.m_path))) {
+ if (!item.m_isFolder &&
+ TFileType::isViewable(TFileType::getInfo(item.m_path))) {
if (isMultipleFrameType(item.m_path.getType()))
item.m_frameCount = m_frameCountReader.getFrameCount(item.m_path);
else
diff --git a/toonz/sources/toonzlib/txshsimplelevel.cpp b/toonz/sources/toonzlib/txshsimplelevel.cpp
index 6dabc84aa..32a02d746 100644
--- a/toonz/sources/toonzlib/txshsimplelevel.cpp
+++ b/toonz/sources/toonzlib/txshsimplelevel.cpp
@@ -1201,6 +1201,16 @@ void TXshSimpleLevel::load() {
assert(lr);
TLevelP level = lr->loadInfo();
+ if (level->isPartialLoad()) {
+ QString msg =
+ QString(
+ "File '%1' partially loaded. Not all frames were found. Possible "
+ "file corruption. Loaded what could be found.\nRecommend "
+ "replacing any bad frames in Level Strip and saving.")
+ .arg(QString::fromStdWString(m_path.getWideString()));
+ QMessageBox::warning(0, "File load warning", msg);
+ setDirtyFlag(true);
+ }
if (level->getFrameCount() > 0) {
const TImageInfo *info = lr->getImageInfo(level->begin()->first);