summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2015-01-01 19:20:41 +0300
committerAndrei Karas <akaras@inbox.ru>2015-01-01 19:20:41 +0300
commit37be713ea07bbe8ddcea10c77bf1bfa2cd74b989 (patch)
treeaef0df6b5a8f8c8dfb6cc05d9580eb9dbb1c03e2 /src
parent4332a501d9a8a1d37913e1236dc1e60702f4b573 (diff)
downloadmanaplus-37be713ea07bbe8ddcea10c77bf1bfa2cd74b989.tar.gz
manaplus-37be713ea07bbe8ddcea10c77bf1bfa2cd74b989.tar.bz2
manaplus-37be713ea07bbe8ddcea10c77bf1bfa2cd74b989.tar.xz
manaplus-37be713ea07bbe8ddcea10c77bf1bfa2cd74b989.zip
Fix crash with completly broken themes.
Diffstat (limited to 'src')
-rw-r--r--src/gui/widgets/characterviewnormal.cpp26
-rw-r--r--src/gui/widgets/characterviewsmall.cpp25
2 files changed, 40 insertions, 11 deletions
diff --git a/src/gui/widgets/characterviewnormal.cpp b/src/gui/widgets/characterviewnormal.cpp
index a8f676af0..ba25e2753 100644
--- a/src/gui/widgets/characterviewnormal.cpp
+++ b/src/gui/widgets/characterviewnormal.cpp
@@ -43,13 +43,25 @@ CharacterViewNormal::CharacterViewNormal(CharSelectDialog *const widget,
add(character);
character->setVisible(true);
}
- if (mSelected >= 0)
- (*mCharacterEntries)[mSelected]->setSelect(false);
- mSelected = 0;
- (*mCharacterEntries)[0]->setSelect(true);
+ const size_t sz = mCharacterEntries->size();
+ if (mSelected >= 0 && mSelected < sz)
+ {
+ CharacterDisplay *const display = (*mCharacterEntries)[mSelected];
+ if (display)
+ display->setSelect(false);
+ }
+ if (sz > 0)
+ {
+ mSelected = 0;
+ CharacterDisplay *const display = (*mCharacterEntries)[0];
+ display->setSelect(true);
+ setWidth(display->getWidth() * 5 + mPadding * 2);
+ }
+ else
+ {
+ mSelected = -1;
+ }
- const CharacterDisplay *const firtChar = (*mCharacterEntries)[0];
- setWidth(firtChar->getWidth() * 5 + mPadding * 2);
}
setHeight(210 + config.getIntValue("fontSize") * 2);
}
@@ -74,6 +86,8 @@ void CharacterViewNormal::show(const int i)
void CharacterViewNormal::resize()
{
const int sz = static_cast<signed>(mCharacterEntries->size());
+ if (sz <= 0)
+ return;
const CharacterDisplay *const firtChar = (*mCharacterEntries)[0];
int y = 0;
const int width = firtChar->getWidth();
diff --git a/src/gui/widgets/characterviewsmall.cpp b/src/gui/widgets/characterviewsmall.cpp
index b68c0171a..7e327c29f 100644
--- a/src/gui/widgets/characterviewsmall.cpp
+++ b/src/gui/widgets/characterviewsmall.cpp
@@ -48,11 +48,21 @@ CharacterViewSmall::CharacterViewSmall(CharSelectDialog *const widget,
add(*it);
}
const int sz = static_cast<signed>(mCharacterEntries->size());
- mSelected = 0;
- mSelectedEntry = (*mCharacterEntries)[mSelected];
- mSelectedEntry->setVisible(true);
- mNumber->setCaption(strprintf("%d / %d", mSelected + 1, sz));
- mNumber->adjustSize();
+ if (sz > 0)
+ {
+ mSelected = 0;
+ mSelectedEntry = (*mCharacterEntries)[mSelected];
+ mSelectedEntry->setVisible(true);
+ mNumber->setCaption(strprintf("%d / %d", mSelected + 1, sz));
+ mNumber->adjustSize();
+ }
+ else
+ {
+ mSelected = -1;
+ mSelectedEntry = nullptr;
+ mNumber->setCaption("0 / 0");
+ mNumber->adjustSize();
+ }
}
add(mPrevious);
add(mNext);
@@ -69,6 +79,8 @@ CharacterViewSmall::~CharacterViewSmall()
void CharacterViewSmall::show(const int i)
{
const int sz = static_cast<signed>(mCharacterEntries->size());
+ if (sz <= 0)
+ return;
if (mSelectedEntry)
mSelectedEntry->setVisible(false);
if (i >= sz)
@@ -85,6 +97,9 @@ void CharacterViewSmall::show(const int i)
void CharacterViewSmall::resize()
{
+ const int sz = static_cast<signed>(mCharacterEntries->size());
+ if (sz <= 0)
+ return;
const CharacterDisplay *const firtChar = (*mCharacterEntries)[0];
const int x = (getWidth() - firtChar->getWidth()) / 2;
const int y = (getHeight() - firtChar->getHeight()) / 2;