Skip to content

Commit

Permalink
Merge topic 'backport-vtkCollection-deserialization-fix' into release
Browse files Browse the repository at this point in the history
5d49f7b Fix deserialization when number of items in collection have not changed

Acked-by: Kitware Robot <[email protected]>
Acked-by: buildbot <[email protected]>
Merge-request: !11677
  • Loading branch information
jspanchu authored and kwrobot committed Dec 11, 2024
2 parents dfcf0a6 + 5d49f7b commit 709c760
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Fix deserialization bug in vtkCollection

Fixes a bug in the deserialization of `vtkRenderer`. When an actor in a renderer was replaced with another actor,
and the scene reserialized with `vtkObjectManager`, the deserializer was unable to detect that the actor had
changed. Instead, the renderer continued to show the old actor. This bug in deserialization of vtkCollection
is now fixed.
12 changes: 2 additions & 10 deletions Wrapping/Tools/vtkWrapSerDesProperty.c
Original file line number Diff line number Diff line change
Expand Up @@ -561,22 +561,14 @@ int vtkWrapSerDes_WritePropertyDeserializer(FILE* fp, const ClassInfo* classInfo
fprintf(fp, " if ((iter != state.end()) && !iter->is_null())\n");
fprintf(fp, " {\n");
fprintf(fp, " const auto items = iter->get<nlohmann::json::array_t>();\n");
fprintf(fp,
" const size_t numExistingItems = static_cast<size_t>(object->GetNumberOf%ss());\n",
keyName);
fprintf(fp, " bool populateCollection = numExistingItems == 0;\n");
fprintf(fp, " if (items.size() != numExistingItems)\n");
fprintf(fp, " {\n");
fprintf(fp, " object->RemoveAll%ss();\n", keyName);
fprintf(fp, " populateCollection = true;\n");
fprintf(fp, " }\n");
fprintf(fp, " object->RemoveAll%ss();\n", keyName);
fprintf(fp, " const auto* context = deserializer->GetContext();\n");
fprintf(fp, " for (const auto& item: items)\n");
fprintf(fp, " {\n");
fprintf(fp, " const auto identifier = item.at(\"Id\").get<vtkTypeUInt32>();\n");
fprintf(fp, " auto subObject = context->GetObjectAtId(identifier);\n");
fprintf(fp, " deserializer->DeserializeJSON(identifier, subObject);\n");
fprintf(fp, " if (populateCollection && subObject != nullptr)\n");
fprintf(fp, " if (subObject != nullptr)\n");
fprintf(fp, " {\n");
fprintf(fp, " auto* itemAsObject = vtkObject::SafeDownCast(subObject);\n");
fprintf(fp, " object->Add%s(reinterpret_cast<%s*>(itemAsObject));\n", keyName,
Expand Down

0 comments on commit 709c760

Please sign in to comment.