diff options
-rw-r--r-- | o3d/core/cross/curve.cc | 10 | ||||
-rw-r--r-- | o3d/core/cross/curve.h | 3 | ||||
-rw-r--r-- | o3d/core/cross/skin.cc | 8 | ||||
-rw-r--r-- | o3d/core/cross/skin.h | 3 |
4 files changed, 24 insertions, 0 deletions
diff --git a/o3d/core/cross/curve.cc b/o3d/core/cross/curve.cc index 9aff37f..5978f9d 100644 --- a/o3d/core/cross/curve.cc +++ b/o3d/core/cross/curve.cc @@ -726,6 +726,7 @@ bool Curve::LoadFromBinaryData(MemoryReadStream *stream) { switch (key_type) { case CurveKey::TYPE_STEP: { if (available_bytes < kStepDataSize) { + FreeAll(); // This must be called before O3D_ERROR. O3D_ERROR(service_locator()) << "unexpected end of curve data"; return false; } @@ -738,6 +739,7 @@ bool Curve::LoadFromBinaryData(MemoryReadStream *stream) { } case CurveKey::TYPE_LINEAR: { if (available_bytes < kLinearDataSize) { + FreeAll(); // This must be called before O3D_ERROR. O3D_ERROR(service_locator()) << "unexpected end of curve data"; return false; } @@ -750,6 +752,7 @@ bool Curve::LoadFromBinaryData(MemoryReadStream *stream) { } case CurveKey::TYPE_BEZIER: { if (available_bytes < kBezierDataSize) { + FreeAll(); // This must be called before O3D_ERROR. O3D_ERROR(service_locator()) << "unexpected end of curve data"; return false; } @@ -765,6 +768,7 @@ bool Curve::LoadFromBinaryData(MemoryReadStream *stream) { break; } default: { + FreeAll(); // This must be called before O3D_ERROR. O3D_ERROR(service_locator()) << "invalid curve data"; return false; // unknown key type } @@ -773,6 +777,12 @@ bool Curve::LoadFromBinaryData(MemoryReadStream *stream) { return true; } +void Curve::FreeAll() { + while (!keys_.empty()) { + keys_[0]->Destroy(); + } +} + bool Curve::Set(o3d::RawData *raw_data) { if (!raw_data) { O3D_ERROR(service_locator()) << "data object is null"; diff --git a/o3d/core/cross/curve.h b/o3d/core/cross/curve.h index 0502dac..855b42c 100644 --- a/o3d/core/cross/curve.h +++ b/o3d/core/cross/curve.h @@ -414,6 +414,9 @@ class Curve : public Function { } } + // Removes all the keys. + void FreeAll(); + // What to do for inputs before the first key Infinity pre_infinity_; diff --git a/o3d/core/cross/skin.cc b/o3d/core/cross/skin.cc index 99387ca..7a29109 100644 --- a/o3d/core/cross/skin.cc +++ b/o3d/core/cross/skin.cc @@ -578,6 +578,7 @@ bool Skin::LoadFromBinaryData(MemoryReadStream *stream) { while (!stream->EndOfStream()) { // Make sure stream has a uint32 to read (for num_influences) if (stream->GetRemainingByteCount() < sizeof(uint32)) { + FreeAll(); // We have to call this before O3D_ERROR. O3D_ERROR(service_locator()) << "unexpected end of skin data"; return false; } @@ -588,6 +589,7 @@ bool Skin::LoadFromBinaryData(MemoryReadStream *stream) { const size_t kInfluenceSize = sizeof(uint32) + sizeof(float); size_t data_size = num_influences * kInfluenceSize; if (stream->GetRemainingByteCount() < data_size) { + FreeAll(); // We have to call this before O3D_ERROR. O3D_ERROR(service_locator()) << "unexpected end of skin data"; return false; } @@ -608,6 +610,12 @@ bool Skin::LoadFromBinaryData(MemoryReadStream *stream) { return true; } +void Skin::FreeAll() { + influences_array_.clear(); + inverse_bind_pose_matrices_.clear(); + info_valid_ = false; +} + bool Skin::Set(o3d::RawData *raw_data) { if (!raw_data) { O3D_ERROR(service_locator()) << "data object is null"; diff --git a/o3d/core/cross/skin.h b/o3d/core/cross/skin.h index 9e0c33f..70193db 100644 --- a/o3d/core/cross/skin.h +++ b/o3d/core/cross/skin.h @@ -152,6 +152,9 @@ class Skin : public NamedObject { // Update the highest influences and highest matrix index. void UpdateInfo() const; + // Frees all the influences and matrices. + void FreeAll(); + // The vertex influences. InfluencesArray influences_array_; |