History

Fix use of EntityTree in import/export operations

The EntityTree needs to be references by a shared_ptr somewhere. The EntityTree does not start with a root element by default, which some operations rely on to work as expected.

Ryan Huffman committed 11 years ago

Commit dde1c8b1 parent 2d477ad1 file · +8 −6Browse files

Showing the changes to interface/src/Application.cpp (1 of 1 file). Show all

Unified · Split

interface/src/Application.cpp+8−6
@@ -2337,7 +2337,8 @@ bool Application::exportEntities(const QString& filename, const QVector<EntityIt · 2336 unmodified lines
23372337 QVector<EntityItemPointer> entities;
23382338
23392339 auto entityTree = _entities.getTree();
2340− EntityTree exportTree;
2340+ auto exportTree = std::make_shared<EntityTree>();
2341+ exportTree->createRootElement();
23412342
23422343 glm::vec3 root(TREE_SCALE, TREE_SCALE, TREE_SCALE);
23432344 for (auto entityID : entityIDs) {
@@ -2364,10 +2365,10 @@ bool Application::exportEntities(const QString& filename, const QVector<EntityIt · 20 unmodified lines
23642365 auto properties = entityItem->getProperties();
23652366
23662367 properties.setPosition(properties.getPosition() - root);
2367− exportTree.addEntity(entityItem->getEntityItemID(), properties);
2368+ exportTree->addEntity(entityItem->getEntityItemID(), properties);
23682369 }
23692370
2370− exportTree.writeToJSONFile(filename.toLocal8Bit().constData());
2371+ exportTree->writeToJSONFile(filename.toLocal8Bit().constData());
23712372
23722373 // restore the main window's active state
23732374 _window->activateWindow();
@@ -2380,15 +2381,16 @@ bool Application::exportEntities(const QString& filename, float x, float y, floa · 6 unmodified lines
23802381
23812382 if (entities.size() > 0) {
23822383 glm::vec3 root(x, y, z);
2383− EntityTree exportTree;
2384+ auto exportTree = std::make_shared<EntityTree>();
2385+ exportTree->createRootElement();
23842386
23852387 for (int i = 0; i < entities.size(); i++) {
23862388 EntityItemProperties properties = entities.at(i)->getProperties();
23872389 EntityItemID id = entities.at(i)->getEntityItemID();
23882390 properties.setPosition(properties.getPosition() - root);
2389− exportTree.addEntity(id, properties);
2391+ exportTree->addEntity(id, properties);
23902392 }
2391− exportTree.writeToSVOFile(filename.toLocal8Bit().constData());
2393+ exportTree->writeToSVOFile(filename.toLocal8Bit().constData());
23922394 } else {
23932395 qCDebug(interfaceapp) << "No models were selected";
23942396 return false;