mirror of
https://github.com/overte-org/overte.git
synced 2025-04-14 07:27:04 +02:00
improved clear() and avoid bad indices
This commit is contained in:
parent
3a4ce9cf5d
commit
59fcee6bc0
4 changed files with 16 additions and 4 deletions
|
@ -46,7 +46,7 @@ void Space::processResets(const Transaction::Resets& transactions) {
|
||||||
auto proxyID = std::get<0>(reset);
|
auto proxyID = std::get<0>(reset);
|
||||||
|
|
||||||
// Guard against proxyID being past the end of the list.
|
// Guard against proxyID being past the end of the list.
|
||||||
if (proxyID < 0 || proxyID >= (int32_t)_proxies.size() || proxyID >= (int32_t)_owners.size()) {
|
if (!_IDAllocator.checkIndex(proxyID)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
auto& item = _proxies[proxyID];
|
auto& item = _proxies[proxyID];
|
||||||
|
@ -61,6 +61,9 @@ void Space::processResets(const Transaction::Resets& transactions) {
|
||||||
|
|
||||||
void Space::processRemoves(const Transaction::Removes& transactions) {
|
void Space::processRemoves(const Transaction::Removes& transactions) {
|
||||||
for (auto removedID : transactions) {
|
for (auto removedID : transactions) {
|
||||||
|
if (!_IDAllocator.checkIndex(removedID)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
_IDAllocator.freeIndex(removedID);
|
_IDAllocator.freeIndex(removedID);
|
||||||
|
|
||||||
// Access the true item
|
// Access the true item
|
||||||
|
@ -75,7 +78,7 @@ void Space::processRemoves(const Transaction::Removes& transactions) {
|
||||||
void Space::processUpdates(const Transaction::Updates& transactions) {
|
void Space::processUpdates(const Transaction::Updates& transactions) {
|
||||||
for (auto& update : transactions) {
|
for (auto& update : transactions) {
|
||||||
auto updateID = std::get<0>(update);
|
auto updateID = std::get<0>(update);
|
||||||
if (updateID == INVALID_PROXY_ID) {
|
if (!_IDAllocator.checkIndex(updateID)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -141,6 +144,7 @@ uint8_t Space::getRegion(int32_t proxyID) const {
|
||||||
}
|
}
|
||||||
|
|
||||||
void Space::clear() {
|
void Space::clear() {
|
||||||
|
Collection::clear();
|
||||||
std::unique_lock<std::mutex> lock(_proxiesMutex);
|
std::unique_lock<std::mutex> lock(_proxiesMutex);
|
||||||
_IDAllocator.clear();
|
_IDAllocator.clear();
|
||||||
_proxies.clear();
|
_proxies.clear();
|
||||||
|
|
|
@ -42,7 +42,7 @@ public:
|
||||||
uint32_t getNumViews() const { return (uint32_t)(_views.size()); }
|
uint32_t getNumViews() const { return (uint32_t)(_views.size()); }
|
||||||
void copyViews(std::vector<View>& copy) const;
|
void copyViews(std::vector<View>& copy) const;
|
||||||
|
|
||||||
uint32_t getNumObjects() const { return _IDAllocator.getNumLiveIndices(); } // (uint32_t)(_proxies.size() - _freeIndices.size()); }
|
uint32_t getNumObjects() const { return _IDAllocator.getNumLiveIndices(); }
|
||||||
uint32_t getNumAllocatedProxies() const { return (uint32_t)(_IDAllocator.getNumAllocatedIndices()); }
|
uint32_t getNumAllocatedProxies() const { return (uint32_t)(_IDAllocator.getNumAllocatedIndices()); }
|
||||||
|
|
||||||
void categorizeAndGetChanges(std::vector<Change>& changes);
|
void categorizeAndGetChanges(std::vector<Change>& changes);
|
||||||
|
@ -51,7 +51,7 @@ public:
|
||||||
const Owner getOwner(int32_t proxyID) const;
|
const Owner getOwner(int32_t proxyID) const;
|
||||||
uint8_t getRegion(int32_t proxyID) const;
|
uint8_t getRegion(int32_t proxyID) const;
|
||||||
|
|
||||||
void clear();
|
void clear() override;
|
||||||
private:
|
private:
|
||||||
|
|
||||||
void processTransactionFrame(const Transaction& transaction) override;
|
void processTransactionFrame(const Transaction& transaction) override;
|
||||||
|
|
|
@ -111,6 +111,12 @@ Collection::Collection() {
|
||||||
Collection::~Collection() {
|
Collection::~Collection() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Collection::clear() {
|
||||||
|
std::unique_lock<std::mutex> lock(_transactionQueueMutex);
|
||||||
|
_transactionQueue.clear();
|
||||||
|
_transactionFrames.clear();
|
||||||
|
}
|
||||||
|
|
||||||
ProxyID Collection::allocateID() {
|
ProxyID Collection::allocateID() {
|
||||||
// Just increment and return the previous value initialized at 0
|
// Just increment and return the previous value initialized at 0
|
||||||
return _IDAllocator.allocateIndex();
|
return _IDAllocator.allocateIndex();
|
||||||
|
|
|
@ -137,6 +137,8 @@ public:
|
||||||
Collection();
|
Collection();
|
||||||
~Collection();
|
~Collection();
|
||||||
|
|
||||||
|
virtual void clear();
|
||||||
|
|
||||||
// This call is thread safe, can be called from anywhere to allocate a new ID
|
// This call is thread safe, can be called from anywhere to allocate a new ID
|
||||||
ProxyID allocateID();
|
ProxyID allocateID();
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue