justburner f2e647
#include <qtimer></qtimer>
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#include "toonz/tscenehandle.h"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#include "toonz/toonzscene.h"
Toshihiro Shimizu 890ddd
#include "toonz/tproject.h"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//=============================================================================
Toshihiro Shimizu 890ddd
// TSceneHandle
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
TSceneHandle::TSceneHandle() : m_scene(0), m_dirtyFlag(false) {}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
TSceneHandle::~TSceneHandle() {}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
ToonzScene *TSceneHandle::getScene() const { return m_scene; }
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void TSceneHandle::setScene(ToonzScene *scene) {
Shinya Kitaoka 120a6e
  if (m_scene == scene) return;
justburner f2e647
  ToonzScene *oldscene = m_scene;
Shinya Kitaoka 120a6e
  m_scene = scene;
Shinya Kitaoka 120a6e
  if (m_scene) emit sceneSwitched();
justburner f2e647
justburner f2e647
  // Prevent memory corruption caused by delayed signals writing into the
justburner f2e647
  // discarded old scene while that memory was freed.
justburner f2e647
  // That made OT had a chance of crashing when project or scene changed rapidly.
justburner f2e647
  // Note: This is not the best solution but "it just works"
justburner f2e647
  if (oldscene) {
justburner f2e647
    QTimer *delayedTimer = new QTimer(this);
justburner f2e647
    delayedTimer->setSingleShot(true);
justburner f2e647
justburner f2e647
    connect(delayedTimer, &QTimer::timeout, [=]() {
justburner f2e647
      delete oldscene;
justburner f2e647
      delayedTimer->deleteLater();
justburner f2e647
    });
justburner f2e647
    delayedTimer->start(3000);  // 1 sec was enough, but... dunno about toasters
justburner f2e647
  }
Toshihiro Shimizu 890ddd
}