Commit 11cba9cc authored by Jan Möbius's avatar Jan Möbius
Browse files

Fixed crash when trying to save object via script with an id that does not exist.

git-svn-id: http://www.openflipper.org/svnrepo/OpenFlipper/branches/Free@20178 383ad7c9-94d9-4d36-a494-682f7c89f535
parent 78d20a62
...@@ -1985,8 +1985,10 @@ int FileOBJPlugin::loadObject(QString _filename, DataType _type){ ...@@ -1985,8 +1985,10 @@ int FileOBJPlugin::loadObject(QString _filename, DataType _type){
bool FileOBJPlugin::saveObject(int _id, QString _filename) bool FileOBJPlugin::saveObject(int _id, QString _filename)
{ {
BaseObjectData* object; BaseObjectData* object;
PluginFunctions::getObject(_id,object); if ( !PluginFunctions::getObject(_id,object) ) {
emit log(LOGERR, tr("saveObject : cannot get object id %1 for save name %2").arg(_id).arg(_filename) );
return false;
}
//open output stream //open output stream
std::string filename = std::string( _filename.toUtf8() ); std::string filename = std::string( _filename.toUtf8() );
......
...@@ -1231,7 +1231,10 @@ int FileOFFPlugin::loadObject(QString _filename, DataType _type) { ...@@ -1231,7 +1231,10 @@ int FileOFFPlugin::loadObject(QString _filename, DataType _type) {
bool FileOFFPlugin::saveObject(int _id, QString _filename) bool FileOFFPlugin::saveObject(int _id, QString _filename)
{ {
BaseObjectData* object; BaseObjectData* object;
PluginFunctions::getObject(_id,object); if ( !PluginFunctions::getObject(_id,object) ) {
emit log(LOGERR, tr("saveObject : cannot get object id %1 for save name %2").arg(_id).arg(_filename) );
return false;
}
std::string filename = std::string( _filename.toUtf8() ); std::string filename = std::string( _filename.toUtf8() );
......
...@@ -447,7 +447,10 @@ void FileOMPlugin::backupTextureCoordinates(MeshT& _mesh) { ...@@ -447,7 +447,10 @@ void FileOMPlugin::backupTextureCoordinates(MeshT& _mesh) {
bool FileOMPlugin::saveObject(int _id, QString _filename) bool FileOMPlugin::saveObject(int _id, QString _filename)
{ {
BaseObjectData* object; BaseObjectData* object;
PluginFunctions::getObject(_id,object); if ( !PluginFunctions::getObject(_id,object) ) {
emit log(LOGERR, tr("saveObject : cannot get object id %1 for save name %2").arg(_id).arg(_filename) );
return false;
}
std::string filename = std::string( _filename.toUtf8() ); std::string filename = std::string( _filename.toUtf8() );
......
...@@ -244,19 +244,29 @@ bool FileOpenVolumeMeshPlugin::saveObject(int _id, QString _filename) { ...@@ -244,19 +244,29 @@ bool FileOpenVolumeMeshPlugin::saveObject(int _id, QString _filename) {
obj->setFromFileName(_filename); obj->setFromFileName(_filename);
obj->setName(obj->filename()); obj->setName(obj->filename());
if(!fileManager_.writeFile(_filename.toStdString(), *(mesh_obj->mesh()))) if(!fileManager_.writeFile(_filename.toStdString(), *(mesh_obj->mesh()))) {
emit log(LOGERR, tr("Unable to save ") + _filename); emit log(LOGERR, tr("Unable to save ") + _filename);
return false;
}
} }
else if (hex_mesh_obj) { else if (hex_mesh_obj) {
obj->setFromFileName(_filename); obj->setFromFileName(_filename);
obj->setName(obj->filename()); obj->setName(obj->filename());
if (!fileManager_.writeFile(_filename.toStdString(), *(hex_mesh_obj->mesh()))) if (!fileManager_.writeFile(_filename.toStdString(), *(hex_mesh_obj->mesh()))) {
emit log(LOGERR, tr("Unable to save ") + _filename); emit log(LOGERR, tr("Unable to save ") + _filename);
return false;
}
} }
return true;
} else {
emit log(LOGERR, tr("saveObject : cannot get object id %1 for save name %2").arg(_id).arg(_filename) );
return false;
} }
return true;
} }
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
......
...@@ -630,7 +630,10 @@ int FilePLYPlugin::loadPolyMeshObject(QString _filename, const PLYHeader& _heade ...@@ -630,7 +630,10 @@ int FilePLYPlugin::loadPolyMeshObject(QString _filename, const PLYHeader& _heade
bool FilePLYPlugin::saveObject(int _id, QString _filename) bool FilePLYPlugin::saveObject(int _id, QString _filename)
{ {
BaseObjectData* object; BaseObjectData* object;
PluginFunctions::getObject(_id,object); if ( !PluginFunctions::getObject(_id,object) ) {
emit log(LOGERR, tr("saveObject : cannot get object id %1 for save name %2").arg(_id).arg(_filename) );
return false;
}
object->setFromFileName(_filename); object->setFromFileName(_filename);
object->setName(object->filename()); object->setName(object->filename());
......
...@@ -77,7 +77,7 @@ ...@@ -77,7 +77,7 @@
// constants of color range drop down box // constants of color range drop down box
static const int COLORRANGE_0_1 = 0; static const int COLORRANGE_0_1 = 0;
static const int COLORRANGE_0_255 = 1; //static const int COLORRANGE_0_255 = 1;
//== IMPLEMENTATION ============================================== //== IMPLEMENTATION ==============================================
......
...@@ -155,6 +155,9 @@ bool FilePlaPlugin::saveObject(int _id, QString _filename) ...@@ -155,6 +155,9 @@ bool FilePlaPlugin::saveObject(int _id, QString _filename)
settings.setValue("YDirection2", plane->planeNode()->yDirection()[2]); settings.setValue("YDirection2", plane->planeNode()->yDirection()[2]);
settings.endGroup(); settings.endGroup();
} }
} else {
emit log(LOGERR, tr("saveObject : cannot get object id %1 for save name %2").arg(_id).arg(_filename) );
return false;
} }
return true; return true;
......
...@@ -121,7 +121,13 @@ bool FilePolyLinePlugin::saveObject(int _id, QString _filename) ...@@ -121,7 +121,13 @@ bool FilePolyLinePlugin::saveObject(int _id, QString _filename)
PolyLineObjectSerializer serializer(pol); PolyLineObjectSerializer serializer(pol);
serializer.serialize(fout); serializer.serialize(fout);
fout.close(); fout.close();
return true;
} else {
return false;
} }
} else {
emit log(LOGERR, tr("saveObject : cannot get object id %1 for save name %2").arg(_id).arg(_filename) );
return false;
} }
return true; return true;
......
...@@ -338,6 +338,9 @@ bool FileSKLPlugin::saveObject(int _id, QString _filename) ...@@ -338,6 +338,9 @@ bool FileSKLPlugin::saveObject(int _id, QString _filename)
obj->setName(obj->filename()); obj->setName(obj->filename());
SaveSkeleton(skel->skeleton(), _filename); SaveSkeleton(skel->skeleton(), _filename);
} }
} else {
emit log(LOGERR, tr("saveObject : cannot get object id %1 for save name %2").arg(_id).arg(_filename) );
return false;
} }
return true; return true;
......
...@@ -186,6 +186,9 @@ bool FileSPHPlugin::saveObject(int _id, QString _filename) ...@@ -186,6 +186,9 @@ bool FileSPHPlugin::saveObject(int _id, QString _filename)
obj->setFromFileName(_filename); obj->setFromFileName(_filename);
obj->setName(obj->filename()); obj->setName(obj->filename());
} }
} else {
emit log(LOGERR, tr("saveObject : cannot get object id %1 for save name %2").arg(_id).arg(_filename) );
return false;
} }
return true; return true;
......
...@@ -172,7 +172,10 @@ int FileSTLPlugin::loadObject(QString _filename) { ...@@ -172,7 +172,10 @@ int FileSTLPlugin::loadObject(QString _filename) {
bool FileSTLPlugin::saveObject(int _id, QString _filename) bool FileSTLPlugin::saveObject(int _id, QString _filename)
{ {
BaseObjectData* object; BaseObjectData* object;
PluginFunctions::getObject(_id,object); if ( !PluginFunctions::getObject(_id,object) ) {
emit log(LOGERR, tr("saveObject : cannot get object id %1 for save name %2").arg(_id).arg(_filename) );
return false;
}
std::string filename = std::string( _filename.toUtf8() ); std::string filename = std::string( _filename.toUtf8() );
......
...@@ -2659,7 +2659,10 @@ int FileVTKPlugin::loadObject(QString _filename, DataType _type){ ...@@ -2659,7 +2659,10 @@ int FileVTKPlugin::loadObject(QString _filename, DataType _type){
bool FileVTKPlugin::saveObject(int _id, QString _filename) { bool FileVTKPlugin::saveObject(int _id, QString _filename) {
BaseObjectData* object; BaseObjectData* object;
PluginFunctions::getObject(_id,object); if ( !PluginFunctions::getObject(_id,object) ) {
emit log(LOGERR, tr("saveObject : cannot get object id %1 for save name %2").arg(_id).arg(_filename) );
return false;
}
std::string filename = std::string( _filename.toUtf8() ); std::string filename = std::string( _filename.toUtf8() );
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment