Permalink
Browse files

Fix #833 Segfault when exporting from CLI with camera layer moved

[Why] The `mLastCameraLayerIdx` didn't point to a camera layer after the layer moved.
[How] If the mLastCameraLayerIdx was not working, pick another camera layer.
  • Loading branch information...
chchwy committed Dec 12, 2017
1 parent 71f0c19 commit 80fec67991fc20e1d6b394d48d2b6ff97ad735d2
Showing with 27 additions and 24 deletions.
  1. +2 −2 app/actioncommands.cpp
  2. +4 −5 app/main.cpp
  3. +18 −14 core_lib/managers/layermanager.cpp
  4. +3 −3 core_lib/managers/layermanager.h
View
@@ -259,7 +259,7 @@ Status ActionCommands::exportImageSequence()
int projectLength = mEditor->layers()->projectLength();
QString sCameraLayerName = dialog->getCameraLayerName();
LayerCamera* cameraLayer = (LayerCamera*)mEditor->layers()->getLayerByName(sCameraLayerName);
LayerCamera* cameraLayer = (LayerCamera*)mEditor->layers()->findLayerByName(sCameraLayerName, Layer::CAMERA);
// Show a progress dialog, as this can take a while if you have lots of frames.
QProgressDialog progress(tr("Exporting image sequence..."), tr("Abort"), 0, 100, mParent);
@@ -326,7 +326,7 @@ Status ActionCommands::exportImage()
// Export
QString sCameraLayerName = dialog->getCameraLayerName();
LayerCamera* cameraLayer = (LayerCamera*)mEditor->layers()->getLayerByName(sCameraLayerName);
LayerCamera* cameraLayer = (LayerCamera*)mEditor->layers()->findLayerByName(sCameraLayerName, Layer::CAMERA);
QTransform view = cameraLayer->getViewAtFrame(mEditor->currentFrame());
View
@@ -23,7 +23,6 @@ GNU General Public License for more details.
#include "mainwindow2.h"
#include "pencilapplication.h"
#include "layermanager.h"
#include "object.h"
void installTranslator( PencilApplication& app )
@@ -230,15 +229,15 @@ int handleArguments( PencilApplication& app )
if ( !parser.value( cameraOption ).isEmpty() )
{
cameraLayer = dynamic_cast<LayerCamera*>( mainWindow.mEditor->object()->findLayerByName( parser.value( cameraOption ), Layer::CAMERA ) );
cameraLayer = dynamic_cast<LayerCamera*>( mainWindow.mEditor->layers()->findLayerByName( parser.value( cameraOption ), Layer::CAMERA ) );
if ( cameraLayer == nullptr )
{
err << PencilApplication::tr("Warning: the specified camera layer %1 was not found, ignoring.").arg( parser.value( cameraOption ) ) << endl;
}
}
if ( cameraLayer == nullptr ) {
int cameraLayerId = mainWindow.mEditor->layers()->getLastCameraLayer();
cameraLayer = dynamic_cast<LayerCamera*>( mainWindow.mEditor->object()->getLayer( cameraLayerId ) );
if ( cameraLayer == nullptr )
{
cameraLayer = dynamic_cast<LayerCamera*>(mainWindow.mEditor->layers()->getLastCameraLayer());
}
for ( int i = 0; i < outputPaths.length(); i++ )
@@ -36,12 +36,12 @@ LayerManager::~LayerManager()
bool LayerManager::init()
{
mLastCameraLayer = 0;
return true;
}
Status LayerManager::load(Object* o)
{
mLastCameraLayerIdx = 0;
emit layerCountChanged(o->getLayerCount());
return Status::OK;
}
@@ -52,9 +52,21 @@ Status LayerManager::save(Object*)
return Status::OK;
}
int LayerManager::getLastCameraLayer()
Layer* LayerManager::getLastCameraLayer()
{
return mLastCameraLayer;
Layer* layer = object()->getLayer(mLastCameraLayerIdx);
if (layer->type() == Layer::CAMERA)
{
return layer;
}
// it's not a camera layer
std::vector<LayerCamera*> camLayers = object()->getLayersByType<LayerCamera>();
if (camLayers.size() > 0)
{
return camLayers[0];
}
return nullptr;
}
Layer* LayerManager::currentLayer()
@@ -74,17 +86,9 @@ Layer* LayerManager::getLayer( int index )
return object()->getLayer(index);
}
Layer* LayerManager::getLayerByName(QString sName)
Layer* LayerManager::findLayerByName(QString sName, Layer::LAYER_TYPE type)
{
auto o = object();
for (int i = 0; i < o->getLayerCount(); ++i)
{
if (o->getLayer(i)->name() == sName)
{
return o->getLayer(i);
}
}
return nullptr;
return object()->findLayerByName(sName, type);
}
int LayerManager::currentLayerIndex()
@@ -113,7 +117,7 @@ void LayerManager::setCurrentLayer( int layerIndex )
{
if ( object()->getLayer( layerIndex )->type() == Layer::CAMERA )
{
mLastCameraLayer = layerIndex;
mLastCameraLayerIdx = layerIndex;
}
}
}
@@ -42,8 +42,8 @@ class LayerManager : public BaseManager
Layer* currentLayer();
Layer* currentLayer(int offset);
Layer* getLayer(int index);
Layer* getLayerByName(QString sName);
int getLastCameraLayer();
Layer* findLayerByName(QString sName, Layer::LAYER_TYPE type = Layer::UNDEFINED);
Layer* getLastCameraLayer();
int currentLayerIndex();
void setCurrentLayer(int nIndex);
void setCurrentLayer(Layer* layer);
@@ -75,7 +75,7 @@ class LayerManager : public BaseManager
private:
int getIndex(Layer*) const;
int mLastCameraLayer = 0;
int mLastCameraLayerIdx = 0;
};
#endif

0 comments on commit 80fec67

Please sign in to comment.