From 5ad85d15da4f8802865a02f917150697b5921a7a Mon Sep 17 00:00:00 2001 From: wmayer Date: Mon, 18 Mar 2024 10:49:30 +0100 Subject: [PATCH] App: InVRMLObject use two different index variables for restoring and saving This is needed as it can happen (e.g. when debugging) that while restoring a project the auto-save mechanism is called that messes up the index value --- src/App/VRMLObject.cpp | 24 ++++++++++++------------ src/App/VRMLObject.h | 3 ++- 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/src/App/VRMLObject.cpp b/src/App/VRMLObject.cpp index 8b7aff85fc..10c1787c28 100644 --- a/src/App/VRMLObject.cpp +++ b/src/App/VRMLObject.cpp @@ -141,7 +141,7 @@ void VRMLObject::Save (Base::Writer &writer) const writer.addFile(url.c_str(), this); } - this->index = 0; + this->indexSave = 0; } void VRMLObject::Restore(Base::XMLReader &reader) @@ -155,14 +155,14 @@ void VRMLObject::Restore(Base::XMLReader &reader) reader.addFile(url.c_str(), this); } - this->index = 0; + this->indexRestore = 0; } void VRMLObject::SaveDocFile (Base::Writer &writer) const { // store the inline files of the VRML file - if (this->index < Urls.getSize()) { - std::string url = Urls[this->index]; + if (this->indexSave < Urls.getSize()) { + std::string url = Urls[this->indexSave]; Base::FileInfo fi(url); // it can happen that the transient directory has changed after @@ -170,12 +170,12 @@ void VRMLObject::SaveDocFile (Base::Writer &writer) const // try again with the new transient directory. if (!fi.exists()) { std::string path = getDocument()->TransientDir.getValue(); - url = Resources[this->index]; + url = Resources[this->indexSave]; url = path + "/" + url; fi.setFile(url); } - this->index++; + this->indexSave++; Base::ifstream file(fi, std::ios::in | std::ios::binary); if (file) { writer.Stream() << file.rdbuf(); @@ -185,18 +185,18 @@ void VRMLObject::SaveDocFile (Base::Writer &writer) const void VRMLObject::RestoreDocFile(Base::Reader &reader) { - if (this->index < Resources.getSize()) { + if (this->indexRestore < Resources.getSize()) { std::string path = getDocument()->TransientDir.getValue(); - std::string url = Resources[this->index]; + std::string url = Resources[this->indexRestore]; std::string intname = this->getNameInDocument(); url = fixRelativePath(intname, url); - Resources.set1Value(this->index, url); + Resources.set1Value(this->indexRestore, url); makeDirectories(path, url); url = path + "/" + url; Base::FileInfo fi(url); - Urls.set1Value(this->index, url); - this->index++; + Urls.set1Value(this->indexRestore, url); + this->indexRestore++; Base::ofstream file(fi, std::ios::out | std::ios::binary); if (file) { @@ -205,7 +205,7 @@ void VRMLObject::RestoreDocFile(Base::Reader &reader) } // after restoring all inline files reload the VRML file - if (this->index == Urls.getSize()) { + if (this->indexRestore == Urls.getSize()) { VrmlFile.touch(); Base::FileInfo fi(VrmlFile.getValue()); this->vrmlPath = fi.dirPath(); diff --git a/src/App/VRMLObject.h b/src/App/VRMLObject.h index 064da42a96..b2d4035a5f 100644 --- a/src/App/VRMLObject.h +++ b/src/App/VRMLObject.h @@ -67,7 +67,8 @@ protected: private: mutable std::string vrmlPath; - mutable int index{0}; + mutable int indexRestore{0}; + mutable int indexSave{0}; }; } //namespace App