Commit 57626416 authored by hybrid's avatar hybrid

Use methods access to avoid out-of-bounds array usage

git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/trunk@4386 dfc29bdd-3216-0410-991c-e03cc46cb475
parent 31e8ed04
...@@ -99,8 +99,10 @@ void CGUISpriteBank::clear() ...@@ -99,8 +99,10 @@ void CGUISpriteBank::clear()
{ {
// drop textures // drop textures
for (u32 i=0; i<Textures.size(); ++i) for (u32 i=0; i<Textures.size(); ++i)
{
if (Textures[i]) if (Textures[i])
Textures[i]->drop(); Textures[i]->drop();
}
Textures.clear(); Textures.clear();
Sprites.clear(); Sprites.clear();
Rectangles.clear(); Rectangles.clear();
...@@ -150,7 +152,7 @@ void CGUISpriteBank::draw2DSprite(u32 index, const core::position2di& pos, ...@@ -150,7 +152,7 @@ void CGUISpriteBank::draw2DSprite(u32 index, const core::position2di& pos,
frame = (f >= Sprites[index].Frames.size()) ? Sprites[index].Frames.size()-1 : f; frame = (f >= Sprites[index].Frames.size()) ? Sprites[index].Frames.size()-1 : f;
} }
const video::ITexture* tex = Textures[Sprites[index].Frames[frame].textureNumber]; const video::ITexture* tex = getTexture(Sprites[index].Frames[frame].textureNumber);
if (!tex) if (!tex)
return; return;
...@@ -182,17 +184,17 @@ void CGUISpriteBank::draw2DSpriteBatch( const core::array<u32>& indices, ...@@ -182,17 +184,17 @@ void CGUISpriteBank::draw2DSpriteBatch( const core::array<u32>& indices,
{ {
const irr::u32 drawCount = core::min_<u32>(indices.size(), pos.size()); const irr::u32 drawCount = core::min_<u32>(indices.size(), pos.size());
if( Textures.empty() ) if (!getTextureCount())
return; return;
core::array<SDrawBatch> drawBatches(Textures.size()); core::array<SDrawBatch> drawBatches(getTextureCount());
for(u32 i = 0;i < Textures.size();i++) for (u32 i=0; i < Textures.size(); ++i)
{ {
drawBatches.push_back(SDrawBatch()); drawBatches.push_back(SDrawBatch());
drawBatches[i].positions.reallocate(drawCount); drawBatches[i].positions.reallocate(drawCount);
drawBatches[i].sourceRects.reallocate(drawCount); drawBatches[i].sourceRects.reallocate(drawCount);
} }
for(u32 i = 0;i < drawCount;i++) for (u32 i = 0; i < drawCount; ++i)
{ {
const u32 index = indices[i]; const u32 index = indices[i];
...@@ -211,7 +213,6 @@ void CGUISpriteBank::draw2DSpriteBatch( const core::array<u32>& indices, ...@@ -211,7 +213,6 @@ void CGUISpriteBank::draw2DSpriteBatch( const core::array<u32>& indices,
} }
const u32 texNum = Sprites[index].Frames[frame].textureNumber; const u32 texNum = Sprites[index].Frames[frame].textureNumber;
SDrawBatch& currentBatch = drawBatches[texNum]; SDrawBatch& currentBatch = drawBatches[texNum];
const u32 rn = Sprites[index].Frames[frame].rectNumber; const u32 rn = Sprites[index].Frames[frame].rectNumber;
...@@ -238,7 +239,7 @@ void CGUISpriteBank::draw2DSpriteBatch( const core::array<u32>& indices, ...@@ -238,7 +239,7 @@ void CGUISpriteBank::draw2DSpriteBatch( const core::array<u32>& indices,
for(u32 i = 0;i < drawBatches.size();i++) for(u32 i = 0;i < drawBatches.size();i++)
{ {
if(!drawBatches[i].positions.empty() && !drawBatches[i].sourceRects.empty()) if(!drawBatches[i].positions.empty() && !drawBatches[i].sourceRects.empty())
Driver->draw2DImageBatch(Textures[i], drawBatches[i].positions, Driver->draw2DImageBatch(getTexture(i), drawBatches[i].positions,
drawBatches[i].sourceRects, clip, color, true); drawBatches[i].sourceRects, clip, color, true);
} }
} }
...@@ -247,4 +248,3 @@ void CGUISpriteBank::draw2DSpriteBatch( const core::array<u32>& indices, ...@@ -247,4 +248,3 @@ void CGUISpriteBank::draw2DSpriteBatch( const core::array<u32>& indices,
} // namespace irr } // namespace irr
#endif // _IRR_COMPILE_WITH_GUI_ #endif // _IRR_COMPILE_WITH_GUI_
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment