diff --git a/modules/softwareintegration/pointdatamessagehandler.cpp b/modules/softwareintegration/pointdatamessagehandler.cpp index bca14271b1..4810b8b306 100644 --- a/modules/softwareintegration/pointdatamessagehandler.cpp +++ b/modules/softwareintegration/pointdatamessagehandler.cpp @@ -82,7 +82,7 @@ void PointDataMessageHandler::handlePointDataMessage(const std::vector& me scripting::ScriptEngine::RemoteScripting::Yes ); }; - addCallback(identifier, { reanchorCallback, { storage::Key::DataPoints } }); + addCallback(identifier, { reanchorCallback, { storage::Key::DataPoints }, "reanchorCallback" }); } void PointDataMessageHandler::handleFixedColorMessage(const std::vector& message, std::shared_ptr connection) { @@ -132,7 +132,7 @@ void PointDataMessageHandler::handleFixedColorMessage(const std::vector& m scripting::ScriptEngine::RemoteScripting::Yes ); }; - addCallback(identifier, { callback }); + addCallback(identifier, { callback, {}, "handleFixedColorMessage" }); } void PointDataMessageHandler::handleColormapMessage(const std::vector& message, std::shared_ptr connection) { @@ -197,7 +197,7 @@ void PointDataMessageHandler::handleColormapMessage(const std::vector& mes ); } }; - addCallback(identifier, { colormapLimitsCallback }); + addCallback(identifier, { colormapLimitsCallback, {}, "colormapLimitsCallback" }); auto enableColormapCallback = [this, identifier] { global::scriptEngine->queueScript( @@ -210,7 +210,7 @@ void PointDataMessageHandler::handleColormapMessage(const std::vector& mes }; // Callback std::vector dataToWaitFor{ storage::Key::Colormap, storage::Key::ColormapAttrData }; - addCallback(identifier, { enableColormapCallback, std::move(dataToWaitFor) }); + addCallback(identifier, { enableColormapCallback, std::move(dataToWaitFor), "enableColormapCallback" }); } void PointDataMessageHandler::handleAttributeDataMessage(const std::vector& message, std::shared_ptr connection) { @@ -250,6 +250,7 @@ void PointDataMessageHandler::handleAttributeDataMessage(const std::vector module->storeData(identifier, key, std::move(attributeData)); + std::string callbackDescription = "handleAttributeDataMessage, key=" + storage::getStorageKeyString(key); switch (key) { case storage::Key::ColormapAttrData : { auto callback = [this, identifier] { @@ -261,7 +262,7 @@ void PointDataMessageHandler::handleAttributeDataMessage(const std::vector scripting::ScriptEngine::RemoteScripting::Yes ); }; - addCallback(identifier, { callback, { key, storage::Key::Colormap } }); + addCallback(identifier, { callback, { key, storage::Key::Colormap }, callbackDescription }); break; } case storage::Key::LinearSizeAttrData: { @@ -274,7 +275,7 @@ void PointDataMessageHandler::handleAttributeDataMessage(const std::vector scripting::ScriptEngine::RemoteScripting::Yes ); }; - addCallback(identifier, { callback, { key } }); + addCallback(identifier, { callback, { key }, callbackDescription }); break; } default: @@ -323,7 +324,7 @@ void PointDataMessageHandler::handleOpacityMessage(const std::vector& mess ); } }; - addCallback(identifier, { callback }); + addCallback(identifier, { callback, {}, "handleOpacityMessage" }); } void PointDataMessageHandler::handleFixedPointSizeMessage(const std::vector& message, std::shared_ptr connection) { @@ -377,7 +378,7 @@ void PointDataMessageHandler::handleFixedPointSizeMessage(const std::vector& message, std::shared_ptr connection) { @@ -443,7 +444,7 @@ void PointDataMessageHandler::handleLinearPointSizeMessage(const std::vectorqueueScript( @@ -458,7 +459,8 @@ void PointDataMessageHandler::handleLinearPointSizeMessage(const std::vector& m auto callback = [this, identifier, visibilityMessage, connection] { // Get renderable - auto r = getRenderable(identifier); + // auto r = getRenderable(identifier); // Get visibility from renderable // properties::Property* enabledProperty = r->property("Enabled"); @@ -500,7 +502,7 @@ void PointDataMessageHandler::handleVisibilityMessage(const std::vector& m scripting::ScriptEngine::RemoteScripting::Yes ); }; - addCallback(identifier, { callback }); + addCallback(identifier, { callback, {}, "handleVisibilityMessage" }); } void PointDataMessageHandler::handleRemoveSGNMessage(const std::vector& message,std::shared_ptr connection) { @@ -555,7 +557,7 @@ void PointDataMessageHandler::postSync() { auto callbacksIt = callbackList.begin(); while (callbacksIt != callbackList.end()) { - auto& [callback, waitForData] = *callbacksIt; + auto& [callback, waitForData, description] = *callbacksIt; try { for (auto& waitFor : waitForData) { @@ -572,8 +574,12 @@ void PointDataMessageHandler::postSync() { } } - callbackMapIt = _onceNodeExistsCallbacks.erase(callbackMapIt); - _onceNodeExistsCallbacksRetries = 0; + if (callbackList.empty()) { + callbackMapIt = _onceNodeExistsCallbacks.erase(callbackMapIt); + _onceNodeExistsCallbacksRetries = 0; + } else { + callbackMapIt++; + } } catch(std::exception &err) { ++_onceNodeExistsCallbacksRetries; @@ -640,7 +646,7 @@ void PointDataMessageHandler::checkRenderable( auto subscriptionCallback = [this, identifier, connection] { subscribeToRenderableUpdates(identifier, connection); }; - addCallback(identifier, { subscriptionCallback }); + addCallback(identifier, { subscriptionCallback, {}, "subscriptionCallback" }); } else { subscribeToRenderableUpdates(identifier, connection); diff --git a/modules/softwareintegration/pointdatamessagehandler.h b/modules/softwareintegration/pointdatamessagehandler.h index 17f9292344..8a4f45644c 100644 --- a/modules/softwareintegration/pointdatamessagehandler.h +++ b/modules/softwareintegration/pointdatamessagehandler.h @@ -39,6 +39,7 @@ class PointDataMessageHandler { struct Callback { std::function function; std::vector waitForData = {}; + std::string description = "???"; // To help debugging. Maybe remove? }; using CallbackList = std::vector; using CallbackMap = std::unordered_map; diff --git a/modules/softwareintegration/softwareintegrationmodule.cpp b/modules/softwareintegration/softwareintegrationmodule.cpp index 008f88e509..898d96f5ba 100644 --- a/modules/softwareintegration/softwareintegrationmodule.cpp +++ b/modules/softwareintegration/softwareintegrationmodule.cpp @@ -115,4 +115,10 @@ std::vector SoftwareIntegrationModule::getSyncables() { return { &_syncableFloatDataStorage }; } + +// Helper function for debugging +std::string SoftwareIntegrationModule::getStringOfAllKeysInStorage() { + return _syncableFloatDataStorage.getStringOfAllKeysInStorage(); +} + } // namespace openspace diff --git a/modules/softwareintegration/softwareintegrationmodule.h b/modules/softwareintegration/softwareintegrationmodule.h index 607b2c0dd3..4af99bec07 100644 --- a/modules/softwareintegration/softwareintegrationmodule.h +++ b/modules/softwareintegration/softwareintegrationmodule.h @@ -57,6 +57,7 @@ public: const SyncableFloatDataStorage::Identifier& identifier, const storage::Key key ); + std::string getStringOfAllKeysInStorage(); std::vector documentations() const override; diff --git a/modules/softwareintegration/syncablefloatdatastorage.cpp b/modules/softwareintegration/syncablefloatdatastorage.cpp index e6e72a8e1d..4b157eae27 100644 --- a/modules/softwareintegration/syncablefloatdatastorage.cpp +++ b/modules/softwareintegration/syncablefloatdatastorage.cpp @@ -68,12 +68,15 @@ void SyncableFloatDataStorage::encode(SyncBuffer* syncBuffer) { for (auto val : storageEntry.data) { syncBuffer->encode(val); } + + // TODO: Maybe combine solution with syncDirty? + storageEntry.hasEncoded = true; } } } void SyncableFloatDataStorage::decode(SyncBuffer* syncBuffer) { - ZoneScopedN("SyncableFloatDataStorage::encode") + ZoneScopedN("SyncableFloatDataStorage::decode") std::lock_guard guard(_mutex); @@ -121,8 +124,9 @@ void SyncableFloatDataStorage::postSync(bool isMaster) { std::lock_guard guard(_mutex); for (auto& sgnStorage : _storage) { for (auto& storageEntry : sgnStorage.second) { - if (storageEntry.second.syncDirty) { + if (storageEntry.second.syncDirty && storageEntry.second.hasEncoded) { storageEntry.second.syncDirty = false; + storageEntry.second.hasEncoded = false; } } } @@ -221,6 +225,20 @@ size_t SyncableFloatDataStorage::count(const Identifier& identifier, const stora return sceneIt->second.count(key); } +// Helper function for debugging +std::string SyncableFloatDataStorage::getStringOfAllKeysInStorage() { + std::string keysString; + + for (auto [id, sceneStorage]: _storage) { + keysString += '(' + id + ')' + ": "; + for(auto [key, val]: sceneStorage) { + keysString += storage::getStorageKeyString(key) + " "; + } + keysString += '\n'; + } + return keysString; +} + /* ================================================== */ } // namespace openspace diff --git a/modules/softwareintegration/syncablefloatdatastorage.h b/modules/softwareintegration/syncablefloatdatastorage.h index 1d3bc42f7d..4a9e69fa3e 100644 --- a/modules/softwareintegration/syncablefloatdatastorage.h +++ b/modules/softwareintegration/syncablefloatdatastorage.h @@ -41,6 +41,7 @@ public: struct Value { // a dataset stored like x1, y1, z1, x2, y2 .... std::vector data; + bool hasEncoded = false; bool syncDirty = true; bool dirty = true; }; @@ -62,6 +63,7 @@ public: bool isDirty(const Identifier& identifier, const storage::Key key); bool isSyncDirty(const Identifier& identifier, const storage::Key key); void store(const Identifier& identifier, const storage::Key key, const ValueData& data); + std::string getStringOfAllKeysInStorage(); private: /* =============== Utility functions ================ */