Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue-423: Crash when editing device dataitem in DeviceModel #424

Merged
merged 4 commits into from
Mar 20, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions src/mtconnect/buffer/checkpoint.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -174,9 +174,17 @@ namespace mtconnect::buffer {
/// @param[in] diMap the map of data ids to data item pointers
void updateDataItems(std::unordered_map<std::string, WeakDataItemPtr> &diMap)
{
for (auto &o : m_observations)
auto iter = m_observations.begin();
while( iter != m_observations.end() )
{
o.second->updateDataItem(diMap);
auto item = *iter;
if( item.second->isOrphan() ) {
iter = m_observations.erase(iter);
}
else {
item.second->updateDataItem(diMap);
iter++;
}
}
}

Expand Down
25 changes: 23 additions & 2 deletions src/mtconnect/buffer/circular_buffer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@
#include "mtconnect/config.hpp"
#include "mtconnect/observation/observation.hpp"
#include "mtconnect/utilities.hpp"
#include "mtconnect/logging.hpp"
#include "mtconnect/entity/requirement.hpp"


namespace mtconnect::buffer {
using SequenceNumber_t = uint64_t;
Expand Down Expand Up @@ -82,11 +85,29 @@ namespace mtconnect::buffer {
/// @param diMap the map of data item ids to new data item entities
void updateDataItems(std::unordered_map<std::string, WeakDataItemPtr> &diMap)
{
for (auto &o : m_slidingBuffer)
std::vector<boost::circular_buffer<observation::ObservationPtr>::iterator> orphanBufferItems;

auto iter = m_slidingBuffer.begin();
while( iter != m_slidingBuffer.end() )
{
o->updateDataItem(diMap);
observation::ObservationPtr o = *iter;
if( o->isOrphan() ) {
orphanBufferItems.push_back(iter);
}
else {
o->updateDataItem(diMap);
}
iter++;
}

// remove orphans from the slidingBuffer
while(!orphanBufferItems.empty()) {
auto orphanIterIter = orphanBufferItems.back();
m_slidingBuffer.erase(orphanIterIter);
wsobel marked this conversation as resolved.
Show resolved Hide resolved
orphanBufferItems.pop_back();
}

// checkpoints will remove orphans from its observations
m_first.updateDataItems(diMap);
m_latest.updateDataItems(diMap);

Expand Down
Loading