From 168a097c8b26e0b60459c3d28d134740c60795cc Mon Sep 17 00:00:00 2001 From: Andrei Kortunov Date: Tue, 19 Jul 2022 23:40:34 +0400 Subject: [PATCH] Improve binding VFS to MyGUI --- components/myguiplatform/myguidatamanager.cpp | 23 +++++++++++++------ 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/components/myguiplatform/myguidatamanager.cpp b/components/myguiplatform/myguidatamanager.cpp index 2f8b0f81e0..70af0774f7 100644 --- a/components/myguiplatform/myguidatamanager.cpp +++ b/components/myguiplatform/myguidatamanager.cpp @@ -10,6 +10,21 @@ #include +namespace +{ + class DataStream final : public MyGUI::DataStream + { + public: + explicit DataStream(std::unique_ptr&& stream) + : MyGUI::DataStream(stream.get()) + , mOwnedStream(std::move(stream)) + {} + + private: + std::unique_ptr mOwnedStream; + }; +} + namespace osgMyGUI { @@ -25,13 +40,7 @@ DataManager::DataManager(const VFS::Manager* vfs) MyGUI::IDataStream *DataManager::getData(const std::string &name) const { - // Note: MyGUI is supposed to read/free input steam itself, - // so copy data from VFS stream to the string stream and pass it to MyGUI. - Files::IStreamPtr streamPtr = mVfs->get(mResourcePath + "/" + name); - std::istream* fileStream = streamPtr.get(); - auto dataStream = std::make_unique(); - *dataStream << fileStream->rdbuf(); - return new MyGUI::DataStream(dataStream.release()); + return new DataStream(mVfs->get(mResourcePath + "/" + name)); } void DataManager::freeData(MyGUI::IDataStream *data)