Skip to content

Commit 54f7b3a

Browse files
committed
Fix Issue #182
1 parent 8df90de commit 54f7b3a

1 file changed

Lines changed: 12 additions & 2 deletions

File tree

src/MaterialStateManager.cxx

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,7 @@ namespace mgis {
368368
check_size(from.size(), to.size());
369369
std::copy(from.begin(), from.end(), to.begin());
370370
}; // end update_span
371-
auto update_field_holder = [&check_size](
371+
auto update_field_holder = [&o, &check_size](
372372
MaterialStateManager::FieldHolder& to,
373373
const MaterialStateManager::FieldHolder& from) {
374374
if (mgis::holds_alternative<mgis::real>(from)) {
@@ -383,6 +383,11 @@ namespace mgis {
383383
} else if(mgis::holds_alternative<std::vector<mgis::real>>(to)) {
384384
// reuse existing memory
385385
auto& to_v = mgis::get<std::vector<mgis::real>>(to);
386+
if (to_v.size() != from_v.size()) {
387+
if (to_v.size() * o.n == from_v.size()) {
388+
to_v.resize(from_v.size());
389+
}
390+
}
386391
check_size(from_v.size(), to_v.size());
387392
std::copy(from_v.begin(), from_v.end(), to_v.begin());
388393
} else {
@@ -399,7 +404,12 @@ namespace mgis {
399404
to_v.begin());
400405
} else if (mgis::holds_alternative<std::vector<mgis::real>>(to)) {
401406
// reuse existing memory
402-
auto to_v = mgis::get<std::vector<mgis::real>>(to);
407+
auto& to_v = mgis::get<std::vector<mgis::real>>(to);
408+
if (to_v.size() != from_v.size()) {
409+
if (to_v.size() * o.n == from_v.size()) {
410+
to_v.resize(from_v.size());
411+
}
412+
}
403413
check_size(from_v.size(), to_v.size());
404414
std::copy(from_v.begin(), from_v.end(),
405415
to_v.begin());

0 commit comments

Comments
 (0)