From 55072c5511b82464823678d37b47b1dcd94594fe Mon Sep 17 00:00:00 2001
From: Jeremy Bullock <jcbullock@gmail.com>
Date: Nov 16 2017 18:46:10 +0000
Subject: Merge pull request #1574 from shun-iwasawa/fix_negative_frame_crash


Fix Crash on Setting Negative Frame
---

diff --git a/toonz/sources/toonz/previewer.cpp b/toonz/sources/toonz/previewer.cpp
index 738bfb2..5ee810c 100644
--- a/toonz/sources/toonz/previewer.cpp
+++ b/toonz/sources/toonz/previewer.cpp
@@ -1139,6 +1139,7 @@ void Previewer::saveRenderedFrames() {
 /*! Restituisce un puntatore al raster randerizzato se il frame e' disponibile,
     altrimenti comincia a calcolarlo*/
 TRasterP Previewer::getRaster(int frame, bool renderIfNeeded) const {
+  if (frame < 0) return TRasterP();
   std::map<int, Imp::FrameInfo>::iterator it = m_imp->m_frames.find(frame);
   if (it != m_imp->m_frames.end()) {
     if (frame < m_imp->m_pbStatus.size()) {
@@ -1183,7 +1184,7 @@ TRasterP Previewer::getRaster(int frame, bool renderIfNeeded) const {
 
 //! Verifica se \b frame e' nella cache, cioe' se il frame e' disponibile
 bool Previewer::isFrameReady(int frame) const {
-  if (frame >= (int)m_imp->m_pbStatus.size()) return false;
+  if (frame < 0 || frame >= (int)m_imp->m_pbStatus.size()) return false;
 
   return m_imp->m_pbStatus[frame] == FlipSlider::PBFrameFinished;
 }
diff --git a/toonz/sources/toonz/viewerpane.cpp b/toonz/sources/toonz/viewerpane.cpp
index da1bfa9..316976c 100644
--- a/toonz/sources/toonz/viewerpane.cpp
+++ b/toonz/sources/toonz/viewerpane.cpp
@@ -205,7 +205,7 @@ void SceneViewerPanel::onDrawFrame(
     }
   }
 
-  assert(frame >= 0);
+  // assert(frame >= 0); // frame can be negative in rare cases
   if (frame != frameHandle->getFrameIndex() + 1) {
     int oldFrame = frameHandle->getFrame();
     frameHandle->setCurrentFrame(frame);