Fixed crash when list is empty. Moved texture blending assignment to Font class.

This commit is contained in:
emb 2015-01-12 12:37:53 -06:00
parent bce77bba23
commit b3efc5526e
2 changed files with 20 additions and 15 deletions

View File

@ -105,26 +105,30 @@ void ScrollingList::SetItems(std::vector<ComponentItemBinding *> *spriteList)
FirstSpriteIndex = 0;
// loop the scroll points if there are not enough
unsigned int originalSize = SpriteList->size();
while(ScrollPoints && ScrollPoints->size()+4 > SpriteList->size())
if(SpriteList)
{
for(unsigned int i = 0; i < originalSize; ++i)
unsigned int originalSize = SpriteList->size();
while(ScrollPoints && ScrollPoints->size()+4 > SpriteList->size() && SpriteList->size() > 0)
{
Item *newItem = new Item();
Item *originalItem = SpriteList->at(i)->GetCollectionItem();
for(unsigned int i = 0; i < originalSize; ++i)
{
Item *newItem = new Item();
Item *originalItem = SpriteList->at(i)->GetCollectionItem();
*newItem = *originalItem;
ComponentItemBinding *newSprite = new ComponentItemBinding(newItem);
SpriteList->push_back(newSprite);
*newItem = *originalItem;
ComponentItemBinding *newSprite = new ComponentItemBinding(newItem);
SpriteList->push_back(newSprite);
}
}
for(unsigned int i = 0; ScrollPoints && i < SelectedSpriteListIndex; ++i)
{
CircularDecrement(FirstSpriteIndex, SpriteList);
}
}
for(unsigned int i = 0; SpriteList && ScrollPoints && i < SelectedSpriteListIndex; ++i)
{
CircularDecrement(FirstSpriteIndex, SpriteList);
}
IsScrollChangedComplete = true;
IsScrollChangedComplete = true;
}
}
void ScrollingList::SetPoints(std::vector<ViewInfo *> *scrollPoints)
@ -313,7 +317,7 @@ void ScrollingList::Update(float dt)
unsigned int numIterations = (ScrollPoints->size() > SpriteList->size()) ? SpriteList->size() : ScrollPoints->size();
unsigned int start = (ScrollPoints->size() > SpriteList->size()) ? SelectedSpriteListIndex : 0;
for(unsigned int i = start; i < start+numIterations; i++)
for(unsigned int i = start; i < start+numIterations && spriteIndex < SpriteList->size(); i++)
{
ComponentItemBinding *s = SpriteList->at(spriteIndex);
unsigned int nextI = GetNextTween(i, ScrollPoints);

View File

@ -136,6 +136,7 @@ bool Font::Initialize(std::string fontPath)
Texture = SDL_CreateTextureFromSurface(SDL::GetRenderer(), atlasSurface);
SDL_FreeSurface(atlasSurface);
SDL_SetTextureBlendMode(Texture, SDL_BLENDMODE_ADD);
SDL_UnlockMutex(SDL::GetMutex());
TTF_CloseFont(font);