|
@@ -188,10 +188,9 @@ Shape::ShapeResult Shape::sRestoreWithChildren(StreamIn &inStream, IDToShapeMap
|
|
|
}
|
|
|
|
|
|
// Check if we already read this shape
|
|
|
- IDToShapeMap::const_iterator shape_it = ioShapeMap.find(shape_id);
|
|
|
- if (shape_it != ioShapeMap.end())
|
|
|
+ if (shape_id < ioShapeMap.size())
|
|
|
{
|
|
|
- result.Set(shape_it->second);
|
|
|
+ result.Set(ioShapeMap[shape_id]);
|
|
|
return result;
|
|
|
}
|
|
|
|
|
@@ -199,7 +198,8 @@ Shape::ShapeResult Shape::sRestoreWithChildren(StreamIn &inStream, IDToShapeMap
|
|
|
result = sRestoreFromBinaryState(inStream);
|
|
|
if (result.HasError())
|
|
|
return result;
|
|
|
- ioShapeMap[shape_id] = result.Get();
|
|
|
+ JPH_ASSERT(ioShapeMap.size() == shape_id); // Assert that this is the next ID in the map
|
|
|
+ ioShapeMap.push_back(result.Get());
|
|
|
|
|
|
// Read the sub shapes
|
|
|
size_t len;
|
|
@@ -237,8 +237,7 @@ Shape::ShapeResult Shape::sRestoreWithChildren(StreamIn &inStream, IDToShapeMap
|
|
|
// Check nullptr
|
|
|
if (material_id != ~uint32(0))
|
|
|
{
|
|
|
- IDToMaterialMap::const_iterator material_it = ioMaterialMap.find(material_id);
|
|
|
- if (material_it == ioMaterialMap.end())
|
|
|
+ if (material_id >= ioMaterialMap.size())
|
|
|
{
|
|
|
// New material, restore material
|
|
|
PhysicsMaterial::PhysicsMaterialResult material_result = PhysicsMaterial::sRestoreFromBinaryState(inStream);
|
|
@@ -248,12 +247,13 @@ Shape::ShapeResult Shape::sRestoreWithChildren(StreamIn &inStream, IDToShapeMap
|
|
|
return result;
|
|
|
}
|
|
|
material = material_result.Get();
|
|
|
- ioMaterialMap[material_id] = material;
|
|
|
+ JPH_ASSERT(material_id == ioMaterialMap.size());
|
|
|
+ ioMaterialMap.push_back(material);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
// Existing material
|
|
|
- material = material_it->second;
|
|
|
+ material = ioMaterialMap[material_id];
|
|
|
}
|
|
|
}
|
|
|
|