Skip to content

Commit 61120bc

Browse files
committed
To avoid memory corruption with debug runtime. And code simplification.
1 parent d8e0393 commit 61120bc

File tree

2 files changed

+23
-27
lines changed

2 files changed

+23
-27
lines changed

src/Layers/xrRender/SkeletonAnimated.cpp

Lines changed: 21 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ extern int psSkeletonUpdate;
1414
using namespace animation;
1515
//////////////////////////////////////////////////////////////////////////
1616
// BoneInstance methods
17-
void CBlendInstance::construct() { ZeroMemory(this, sizeof(*this)); }
17+
void CBlendInstance::construct() { Blend.clear(); }
1818
void CBlendInstance::blend_add(CBlend* H)
1919
{
2020
if (Blend.size() == MAX_BLENDED)
@@ -41,14 +41,14 @@ void CBlendInstance::blend_remove(CBlend* H)
4141
void CKinematicsAnimated::Bone_Motion_Start(CBoneData* bd, CBlend* handle)
4242
{
4343
LL_GetBlendInstance(bd->GetSelfID()).blend_add(handle);
44-
for (vecBonesIt I = bd->children.begin(); I != bd->children.end(); I++)
45-
Bone_Motion_Start(*I, handle);
44+
for (auto &it : bd->children)
45+
Bone_Motion_Start(it, handle);
4646
}
4747
void CKinematicsAnimated::Bone_Motion_Stop(CBoneData* bd, CBlend* handle)
4848
{
4949
LL_GetBlendInstance(bd->GetSelfID()).blend_remove(handle);
50-
for (vecBonesIt I = bd->children.begin(); I != bd->children.end(); I++)
51-
Bone_Motion_Stop(*I, handle);
50+
for (auto &it : bd->children)
51+
Bone_Motion_Stop(it, handle);
5252
}
5353
void CKinematicsAnimated::Bone_Motion_Start_IM(CBoneData* bd, CBlend* handle)
5454
{
@@ -64,10 +64,9 @@ void CKinematicsAnimated::Bone_Motion_Stop_IM(CBoneData* bd, CBlend* handle)
6464
std::pair<LPCSTR, LPCSTR> CKinematicsAnimated::LL_MotionDefName_dbg(MotionID ID)
6565
{
6666
shared_motions& s_mots = m_Motions[ID.slot].motions;
67-
accel_map::iterator _I, _E = s_mots.motion_map()->end();
68-
for (_I = s_mots.motion_map()->begin(); _I != _E; ++_I)
69-
if (_I->second == ID.idx)
70-
return std::make_pair(*_I->first, *s_mots.id());
67+
for (auto &it : *s_mots.motion_map())
68+
if (it.second == ID.idx)
69+
return std::make_pair(*it.first, *s_mots.id());
7170
return std::make_pair((LPCSTR)nullptr, (LPCSTR)nullptr);
7271
}
7372

@@ -110,9 +109,8 @@ static void dump_blend(CKinematicsAnimated* K, CBlend& B, u32 index)
110109
void CKinematicsAnimated::LL_DumpBlends_dbg()
111110
{
112111
Msg("==================dump blends=================================================");
113-
CBlend *I = blend_pool.begin(), *E = blend_pool.end();
114-
for (; I != E; I++)
115-
dump_blend(this, *I, u32(I - blend_pool.begin()));
112+
for (auto &it : blend_pool)
113+
dump_blend(this, it, u32(&it - blend_pool.begin()));
116114
}
117115

118116
#endif
@@ -126,10 +124,9 @@ CBlend* CKinematicsAnimated::LL_PartBlend(u32 bone_part_id, u32 n)
126124
}
127125
void CKinematicsAnimated::LL_IterateBlends(IterateBlendsCallback& callback)
128126
{
129-
CBlend *I = blend_pool.begin(), *E = blend_pool.end();
130-
for (; I != E; I++)
131-
if (I->blend_state() != CBlend::eFREE_SLOT)
132-
callback(*I);
127+
for (auto &it : blend_pool)
128+
if (it.blend_state() != CBlend::eFREE_SLOT)
129+
callback(it);
133130
}
134131
/*
135132
LPCSTR CKinematicsAnimated::LL_MotionDefName_dbg (LPVOID ptr)
@@ -705,10 +702,9 @@ CBlend* CKinematicsAnimated::IBlend_Create()
705702
{
706703
UpdateTracks();
707704
_DBG_SINGLE_USE_MARKER;
708-
CBlend *I = blend_pool.begin(), *E = blend_pool.end();
709-
for (; I != E; I++)
710-
if (I->blend_state() == CBlend::eFREE_SLOT)
711-
return I;
705+
for (auto &it : blend_pool)
706+
if (it.blend_state() == CBlend::eFREE_SLOT)
707+
return &it;
712708
FATAL("Too many blended motions requisted");
713709
return nullptr;
714710
}
@@ -819,9 +815,9 @@ void CKinematicsAnimated::Load(const char* N, IReader* data, u32 dwFlags)
819815
m_Partition->load(this, N);
820816

821817
// initialize motions
822-
for (auto m_it = m_Motions.begin(); m_it != m_Motions.end(); m_it++)
818+
for (auto &m_it : m_Motions)
823819
{
824-
SMotionsSlot& MS = *m_it;
820+
SMotionsSlot& MS = m_it;
825821
MS.bone_motions.resize(bones->size());
826822
for (u32 i = 0; i < bones->size(); i++)
827823
{
@@ -843,10 +839,10 @@ void CKinematicsAnimated::LL_BuldBoneMatrixDequatize(const CBoneData* bd, u8 cha
843839
CBlendInstance& BLEND_INST = LL_GetBlendInstance(SelfID);
844840
const CBlendInstance::BlendSVec& Blend = BLEND_INST.blend_vector();
845841
CKey BK[MAX_CHANNELS][MAX_BLENDED]; // base keys
846-
BlendSVecCIt BI;
847-
for (BI = Blend.begin(); BI != Blend.end(); BI++)
842+
843+
for (auto &it : Blend)
848844
{
849-
CBlend* B = *BI;
845+
CBlend* B = it;
850846
int& b_count = keys.chanel_blend_conts[B->channel];
851847
CKey* D = &keys.keys[B->channel][b_count];
852848
if (!(channel_mask & (1 << B->channel)))

src/Layers/xrRender/SkeletonAnimated.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ class CBlendInstance // Bone Instance Blend List (per-bone data)
3030
u32 mem_usage()
3131
{
3232
u32 sz = sizeof(*this);
33-
for (BlendSVecIt it = Blend.begin(); it != Blend.end(); it++)
34-
sz += (*it)->mem_usage();
33+
for (auto &it : Blend)
34+
sz += it->mem_usage();
3535
return sz;
3636
}
3737
};

0 commit comments

Comments
 (0)