Skip to content

Commit

Permalink
Fix: AgentVector::internal_resize() would reduce size without updatin…
Browse files Browse the repository at this point in the history
…g size()

Noticed this whilst resolving it's copy-paste comment, no evidence it was used in this manner. Full test suite still passes.
  • Loading branch information
Robadob committed Dec 10, 2024
1 parent c3f3574 commit 907fc52
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 10 deletions.
7 changes: 4 additions & 3 deletions include/flamegpu/simulation/AgentVector.h
Original file line number Diff line number Diff line change
Expand Up @@ -600,9 +600,10 @@ class AgentVector {
*/
virtual void _requireLength() const { }
/**
* Notify any subclasses that all variables are about to be accessed
* Should be called by operations which move agents (e.g. insert/erase)
* @note This is not called in conjunction with _insert() or _erase()
* Resize the capacity of the AgentVector
* @param count The new capacity of the agent vector
* @param init Whether any new agents should be default init
* @note If count < size() agent data will be lost
*/
void internal_resize(size_type count, bool init);
/**
Expand Down
9 changes: 2 additions & 7 deletions src/flamegpu/simulation/AgentVector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -543,13 +543,6 @@ void AgentVector::internal_resize(size_type count, bool init) {
// Need to create the variable's vector
auto t = std::unique_ptr<detail::GenericMemoryVector>(v.second.memory_vector->clone());
t->resize(count);
// Default init all new elements
if (init) {
char* t_data = static_cast<char*>(t->getDataPtr());
for (unsigned int i = 0; i < count; ++i) {
memcpy(t_data + i * variable_size, v.second.default_value, variable_size);
}
}
_data->emplace(v.first, std::move(t));
} else {
// Need to resize the variables vector
Expand All @@ -561,6 +554,8 @@ void AgentVector::internal_resize(size_type count, bool init) {
// Default init all new elements
if (init && count > old_capacity) {
this->init(old_capacity, _capacity);
} else if (count < old_capacity) {
_size = count;
}
}
void AgentVector::swap(AgentVector& other) noexcept {
Expand Down

0 comments on commit 907fc52

Please sign in to comment.