summaryrefslogtreecommitdiff
path: root/src/gui
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2015-07-11 00:12:09 +0300
committerAndrei Karas <akaras@inbox.ru>2015-07-11 00:12:09 +0300
commit4fbb944f132eb886a6f5b350e5a14a4fe380aacf (patch)
tree6df2ed96430610ee7c35a7ca4902bbdade0e8e34 /src/gui
parent1dc012a3bb44218778568e8f80c4e9b445802195 (diff)
downloadmv-4fbb944f132eb886a6f5b350e5a14a4fe380aacf.tar.gz
mv-4fbb944f132eb886a6f5b350e5a14a4fe380aacf.tar.bz2
mv-4fbb944f132eb886a6f5b350e5a14a4fe380aacf.tar.xz
mv-4fbb944f132eb886a6f5b350e5a14a4fe380aacf.zip
Add missing checks into gui.
Diffstat (limited to 'src/gui')
-rw-r--r--src/gui/dialogsmanager.h2
-rw-r--r--src/gui/focushandler.cpp4
-rw-r--r--src/gui/gui.cpp58
-rw-r--r--src/gui/gui.h14
-rw-r--r--src/gui/models/beingslistmodel.h2
-rw-r--r--src/gui/models/colormodel.cpp2
-rw-r--r--src/gui/models/colormodel.h9
-rw-r--r--src/gui/widgets/colorpage.cpp3
-rw-r--r--src/gui/widgets/itemcontainer.cpp34
-rw-r--r--src/gui/widgets/label.cpp7
-rw-r--r--src/gui/widgets/listbox.cpp5
-rw-r--r--src/gui/widgets/scrollarea.cpp2
-rw-r--r--src/gui/widgets/setupitem.h2
-rw-r--r--src/gui/widgets/tabbedarea.cpp33
-rw-r--r--src/gui/widgets/tabs/socialfriendstab.h2
-rw-r--r--src/gui/widgets/tabs/socialnavigationtab.h15
-rw-r--r--src/gui/widgets/tabs/socialplayerstab.h6
-rw-r--r--src/gui/widgets/tabstrip.cpp2
-rw-r--r--src/gui/widgets/widget.h4
-rw-r--r--src/gui/widgets/window.cpp13
-rw-r--r--src/gui/windows/buydialog.cpp13
-rw-r--r--src/gui/windows/chatwindow.cpp21
-rw-r--r--src/gui/windows/minimap.cpp2
-rw-r--r--src/gui/windows/skilldialog.cpp2
-rw-r--r--src/gui/windows/statuswindow.cpp2
-rw-r--r--src/gui/windows/textdialog.cpp16
26 files changed, 135 insertions, 140 deletions
diff --git a/src/gui/dialogsmanager.h b/src/gui/dialogsmanager.h
index 4dd4bcf7b..cc42c08d5 100644
--- a/src/gui/dialogsmanager.h
+++ b/src/gui/dialogsmanager.h
@@ -46,7 +46,7 @@ class DialogsManager final : public AttributeListener,
static Window *openErrorDialog(const std::string &header,
const std::string &message,
- const Modal modal);
+ const Modal modal) RETURNS_NONNULL;
void playerDeath() override final;
diff --git a/src/gui/focushandler.cpp b/src/gui/focushandler.cpp
index 41cea3a82..667cb81d0 100644
--- a/src/gui/focushandler.cpp
+++ b/src/gui/focushandler.cpp
@@ -339,6 +339,8 @@ void FocusHandler::distributeFocusGainedEvent(const Event &focusEvent)
Widget *const sourceWidget = focusEvent.getSource();
+ if (!sourceWidget)
+ return;
std::list<FocusListener*> focusListeners
= sourceWidget->getFocusListeners();
@@ -550,6 +552,8 @@ void FocusHandler::focusNone()
void FocusHandler::distributeFocusLostEvent(const Event& focusEvent)
{
Widget *const sourceWidget = focusEvent.getSource();
+ if (!sourceWidget)
+ return;
std::list<FocusListener*> focusListeners
= sourceWidget->getFocusListeners();
diff --git a/src/gui/gui.cpp b/src/gui/gui.cpp
index 91224b714..50a0a6a28 100644
--- a/src/gui/gui.cpp
+++ b/src/gui/gui.cpp
@@ -117,11 +117,11 @@ Gui::Gui() :
mLastMouseDragButton(MouseButton::EMPTY),
mWidgetWithMouseQueue(),
mConfigListener(new GuiConfigListener(this)),
- mGuiFont(),
- mInfoParticleFont(),
- mHelpFont(),
- mSecureFont(),
- mNpcFont(),
+ mGuiFont(nullptr),
+ mInfoParticleFont(nullptr),
+ mHelpFont(nullptr),
+ mSecureFont(nullptr),
+ mNpcFont(nullptr),
mMouseCursors(nullptr),
mMouseCursorAlpha(1.0F),
mMouseInactivityTimer(0),
@@ -455,6 +455,8 @@ void Gui::draw()
{
BLOCK_START("Gui::draw 1")
Widget *const top = getTop();
+ if (!top)
+ return;
mGraphics->pushClipArea(top->getDimension());
if (isBatchDrawRenders(openGLMode))
@@ -661,7 +663,8 @@ void Gui::handleMouseMoved(const MouseInput &mouseInput)
// mouse entered events.
if (mFocusHandler->getModalMouseInputFocused()
&& widget == mFocusHandler->getModalMouseInputFocused()
- && Widget::widgetExists(widget))
+ && Widget::widgetExists(widget) &&
+ widget)
{
int x, y;
widget->getAbsolutePosition(x, y);
@@ -742,6 +745,8 @@ void Gui::handleMousePressed(const MouseInput &mouseInput)
if (mFocusHandler->getDraggedWidget())
sourceWidget = mFocusHandler->getDraggedWidget();
+ if (!sourceWidget)
+ return;
int sourceWidgetX;
int sourceWidgetY;
sourceWidget->getAbsolutePosition(sourceWidgetX, sourceWidgetY);
@@ -1038,7 +1043,7 @@ void Gui::handleMouseReleased(const MouseInput &mouseInput)
Widget *const oldWidget = sourceWidget;
sourceWidget = mFocusHandler->getDraggedWidget();
- if (oldWidget != sourceWidget)
+ if (oldWidget && oldWidget != sourceWidget)
{
oldWidget->getAbsolutePosition(sourceWidgetX, sourceWidgetY);
distributeMouseEvent(oldWidget,
@@ -1049,6 +1054,8 @@ void Gui::handleMouseReleased(const MouseInput &mouseInput)
}
}
+ if (!sourceWidget)
+ return;
sourceWidget->getAbsolutePosition(sourceWidgetX, sourceWidgetY);
distributeMouseEvent(sourceWidget,
MouseEventType::RELEASED,
@@ -1165,13 +1172,16 @@ void Gui::handleMouseWheelMovedDown(const MouseInput& mouseInput)
int sourceWidgetX = 0;
int sourceWidgetY = 0;
- sourceWidget->getAbsolutePosition(sourceWidgetX, sourceWidgetY);
+ if (sourceWidget)
+ {
+ sourceWidget->getAbsolutePosition(sourceWidgetX, sourceWidgetY);
- distributeMouseEvent(sourceWidget,
- MouseEventType::WHEEL_MOVED_DOWN,
- mouseInput.getButton(),
- mouseInput.getX(),
- mouseInput.getY());
+ distributeMouseEvent(sourceWidget,
+ MouseEventType::WHEEL_MOVED_DOWN,
+ mouseInput.getButton(),
+ mouseInput.getX(),
+ mouseInput.getY());
+ }
}
void Gui::handleMouseWheelMovedUp(const MouseInput& mouseInput)
@@ -1182,14 +1192,17 @@ void Gui::handleMouseWheelMovedUp(const MouseInput& mouseInput)
if (mFocusHandler->getDraggedWidget())
sourceWidget = mFocusHandler->getDraggedWidget();
- int sourceWidgetX, sourceWidgetY;
- sourceWidget->getAbsolutePosition(sourceWidgetX, sourceWidgetY);
-
- distributeMouseEvent(sourceWidget,
- MouseEventType::WHEEL_MOVED_UP,
- mouseInput.getButton(),
- mouseInput.getX(),
- mouseInput.getY());
+ int sourceWidgetX;
+ int sourceWidgetY;
+ if (sourceWidget)
+ {
+ sourceWidget->getAbsolutePosition(sourceWidgetX, sourceWidgetY);
+ distributeMouseEvent(sourceWidget,
+ MouseEventType::WHEEL_MOVED_UP,
+ mouseInput.getButton(),
+ mouseInput.getX(),
+ mouseInput.getY());
+ }
}
Widget* Gui::getWidgetAt(const int x, const int y) const
@@ -1243,9 +1256,10 @@ void Gui::distributeKeyEvent(KeyEvent &event) const
Widget* parent = event.getSource();
Widget* widget = parent;
+ if (!parent)
+ return;
if (mFocusHandler->getModalFocused() && !widget->isModalFocused())
return;
-
if (mFocusHandler->getModalMouseInputFocused()
&& !widget->isModalMouseInputFocused())
{
diff --git a/src/gui/gui.h b/src/gui/gui.h
index 209c40749..ea9dae7ef 100644
--- a/src/gui/gui.h
+++ b/src/gui/gui.h
@@ -156,32 +156,32 @@ class Gui final
/**
* Return game font.
*/
- Font *getFont() const A_WARN_UNUSED
+ Font *getFont() const RETURNS_NONNULL A_WARN_UNUSED
{ return mGuiFont; }
/**
* Return help font.
*/
- Font *getHelpFont() const A_WARN_UNUSED
+ Font *getHelpFont() const RETURNS_NONNULL A_WARN_UNUSED
{ return mHelpFont; }
/**
* Return secure font.
*/
- Font *getSecureFont() const A_WARN_UNUSED
+ Font *getSecureFont() const RETURNS_NONNULL A_WARN_UNUSED
{ return mSecureFont; }
/**
* Return npc font.
*/
- Font *getNpcFont() const A_WARN_UNUSED
+ Font *getNpcFont() const RETURNS_NONNULL A_WARN_UNUSED
{ return mNpcFont; }
/**
* Return the Font used for "Info Particles", i.e. ones showing, what
* you picked up, etc.
*/
- Font *getInfoParticleFont() const A_WARN_UNUSED
+ Font *getInfoParticleFont() const RETURNS_NONNULL A_WARN_UNUSED
{ return mInfoParticleFont; }
/**
@@ -257,7 +257,7 @@ class Gui final
* OpenLayerGraphics, OpenGLGraphics, SDLGraphics
* @since 0.1.0
*/
- void setGraphics(Graphics *const graphics);
+ void setGraphics(Graphics *const graphics) A_NONNULL(2);
/**
* Gets the graphics object used for drawing.
@@ -268,7 +268,7 @@ class Gui final
* OpenLayerGraphics, OpenGLGraphics, SDLGraphics
* @since 0.1.0
*/
- Graphics* getGraphics() const A_WARN_UNUSED;
+ Graphics* getGraphics() const RETURNS_NONNULL A_WARN_UNUSED;
/**
* Sets the input object to use for input handling.
diff --git a/src/gui/models/beingslistmodel.h b/src/gui/models/beingslistmodel.h
index 7e8caced2..4d587d763 100644
--- a/src/gui/models/beingslistmodel.h
+++ b/src/gui/models/beingslistmodel.h
@@ -43,7 +43,7 @@ class BeingsListModel final : public AvatarListModel
mMembers.clear();
}
- std::vector<Avatar*> *getMembers()
+ std::vector<Avatar*> *getMembers() RETURNS_NONNULL A_WARN_UNUSED
{
return &mMembers;
}
diff --git a/src/gui/models/colormodel.cpp b/src/gui/models/colormodel.cpp
index f7b18d300..a31b245c4 100644
--- a/src/gui/models/colormodel.cpp
+++ b/src/gui/models/colormodel.cpp
@@ -51,7 +51,7 @@ std::string ColorModel::getElementAt(int i)
const ColorPair *ColorModel::getColorAt(const int i) const
{
if (i >= static_cast<int>(mColors.size()) || i < 0)
- return nullptr;
+ return &mColors[0];
return &mColors[i];
}
diff --git a/src/gui/models/colormodel.h b/src/gui/models/colormodel.h
index 81d8d8cbe..9537d7766 100644
--- a/src/gui/models/colormodel.h
+++ b/src/gui/models/colormodel.h
@@ -45,7 +45,8 @@ class ColorModel final : public ListModel
std::string getElementAt(int i) override final A_WARN_UNUSED;
- virtual const ColorPair *getColorAt(const int i) const A_WARN_UNUSED;
+ const ColorPair *getColorAt(const int i)
+ const RETURNS_NONNULL A_WARN_UNUSED;
StringVect &getNames() A_WARN_UNUSED
{ return mNames; }
@@ -53,10 +54,12 @@ class ColorModel final : public ListModel
size_t size() A_WARN_UNUSED
{ return mNames.size(); }
- void add(const std::string &name, const Color *const color1,
+ void add(const std::string &name,
+ const Color *const color1,
const Color *const color2);
- static ColorModel *createDefault(const Widget2 *const widget);
+ static ColorModel *createDefault(const Widget2 *const widget)
+ RETURNS_NONNULL;
protected:
StringVect mNames;
diff --git a/src/gui/widgets/colorpage.cpp b/src/gui/widgets/colorpage.cpp
index 6897399d5..d50f49968 100644
--- a/src/gui/widgets/colorpage.cpp
+++ b/src/gui/widgets/colorpage.cpp
@@ -36,8 +36,7 @@ ColorPage::ColorPage(const Widget2 *const widget,
mItemPadding = mSkin ? mSkin->getOption("itemPadding") : 1;
mRowHeight = 13;
const Font *const font = getFont();
- if (font)
- mRowHeight = font->getHeight() + 2 * mItemPadding;
+ mRowHeight = font->getHeight() + 2 * mItemPadding;
if (mListModel)
{
setHeight(getRowHeight() * mListModel->getNumberOfElements()
diff --git a/src/gui/widgets/itemcontainer.cpp b/src/gui/widgets/itemcontainer.cpp
index 7e9049aa0..17c0d9cf1 100644
--- a/src/gui/widgets/itemcontainer.cpp
+++ b/src/gui/widgets/itemcontainer.cpp
@@ -616,18 +616,21 @@ void ItemContainer::mouseReleased(MouseEvent &event)
#endif
{
inventory = PlayerInfo::getInventory();
- const Item *const item = inventory->getItem(dragDrop.getTag());
- if (item && !PlayerInfo::isItemProtected(item->getId()))
+ if (inventory)
{
- mInventory->addItem(item->getId(), item->getType(),
- 1,
- 1,
- item->getColor(),
- item->getIdentified(),
- item->getDamaged(),
- item->getFavorite(),
- Equipm_false,
- Equipped_false);
+ const Item *const item = inventory->getItem(dragDrop.getTag());
+ if (item && !PlayerInfo::isItemProtected(item->getId()))
+ {
+ mInventory->addItem(item->getId(), item->getType(),
+ 1,
+ 1,
+ item->getColor(),
+ item->getIdentified(),
+ item->getDamaged(),
+ item->getFavorite(),
+ Equipm_false,
+ Equipped_false);
+ }
}
return;
}
@@ -638,9 +641,12 @@ void ItemContainer::mouseReleased(MouseEvent &event)
#endif
{
inventory = PlayerInfo::getInventory();
- const Item *const item = inventory->getItem(dragDrop.getTag());
- if (item)
- mInventory->removeItemAt(dragDrop.getTag());
+ if (inventory)
+ {
+ const Item *const item = inventory->getItem(dragDrop.getTag());
+ if (item)
+ mInventory->removeItemAt(dragDrop.getTag());
+ }
return;
}
diff --git a/src/gui/widgets/label.cpp b/src/gui/widgets/label.cpp
index 722e1bbe9..8f0d49887 100644
--- a/src/gui/widgets/label.cpp
+++ b/src/gui/widgets/label.cpp
@@ -99,11 +99,8 @@ Label::Label(const Widget2 *const widget,
mTextChanged(true)
{
const Font *const font = getFont();
- if (font)
- {
- setWidth(font->getWidth(caption));
- setHeight(font->getHeight());
- }
+ setWidth(font->getWidth(caption));
+ setHeight(font->getHeight());
init();
}
diff --git a/src/gui/widgets/listbox.cpp b/src/gui/widgets/listbox.cpp
index 85e1a5b8f..6204102c4 100644
--- a/src/gui/widgets/listbox.cpp
+++ b/src/gui/widgets/listbox.cpp
@@ -122,10 +122,7 @@ ListBox::ListBox(const Widget2 *const widget,
}
const Font *const font = getFont();
- if (font)
- mRowHeight = font->getHeight() + 2 * mItemPadding;
- else
- mRowHeight = 13;
+ mRowHeight = font->getHeight() + 2 * mItemPadding;
}
void ListBox::postInit()
diff --git a/src/gui/widgets/scrollarea.cpp b/src/gui/widgets/scrollarea.cpp
index 1e43b31b5..df05ec3fa 100644
--- a/src/gui/widgets/scrollarea.cpp
+++ b/src/gui/widgets/scrollarea.cpp
@@ -1276,7 +1276,7 @@ void ScrollArea::setScrollbarWidth(const int width)
void ScrollArea::showWidgetPart(Widget *const widget, const Rect &area)
{
const Widget *const content = getContent();
- if (widget != content)
+ if (widget != content || !content)
return;
BasicContainer::showWidgetPart(widget, area);
diff --git a/src/gui/widgets/setupitem.h b/src/gui/widgets/setupitem.h
index bc6443bb3..0853c6f19 100644
--- a/src/gui/widgets/setupitem.h
+++ b/src/gui/widgets/setupitem.h
@@ -71,7 +71,7 @@ class SetupItem notfinal : public ActionListener,
Widget *getWidget() const A_WARN_UNUSED
{ return mWidget; }
- Configuration *getConfig() const A_WARN_UNUSED;
+ Configuration *getConfig() const RETURNS_NONNULL A_WARN_UNUSED;
virtual std::string getActionEventId() const A_WARN_UNUSED;
diff --git a/src/gui/widgets/tabbedarea.cpp b/src/gui/widgets/tabbedarea.cpp
index b6b0eceb4..33f07efe8 100644
--- a/src/gui/widgets/tabbedarea.cpp
+++ b/src/gui/widgets/tabbedarea.cpp
@@ -455,28 +455,25 @@ void TabbedArea::widgetResized(const Event &event A_UNUSED)
- mWidgetContainer->getY() - widgetFrameSize;
Widget *const w = getCurrentWidget();
- if (w)
+ ScrollArea *const scr = dynamic_cast<ScrollArea *const>(w);
+ if (scr)
{
- ScrollArea *const scr = dynamic_cast<ScrollArea *const>(w);
- if (scr)
+ if (mFollowDownScroll && height != 0)
{
- if (mFollowDownScroll && height != 0)
+ const Rect &rect = w->getDimension();
+ if (rect.height != 0 && rect.height > height + 2)
{
- const Rect &rect = w->getDimension();
- if (rect.height != 0 && rect.height > height + 2)
+ if (scr->getVerticalScrollAmount()
+ >= scr->getVerticalMaxScroll() - 2
+ && scr->getVerticalScrollAmount()
+ <= scr->getVerticalMaxScroll() + 2)
{
- if (scr->getVerticalScrollAmount()
- >= scr->getVerticalMaxScroll() - 2
- && scr->getVerticalScrollAmount()
- <= scr->getVerticalMaxScroll() + 2)
- {
- const int newScroll = scr->getVerticalScrollAmount()
- + rect.height - height;
- w->setSize(mWidgetContainer->getWidth() - frameSize,
- mWidgetContainer->getHeight() - frameSize);
- if (newScroll)
- scr->setVerticalScrollAmount(newScroll);
- }
+ const int newScroll = scr->getVerticalScrollAmount()
+ + rect.height - height;
+ w->setSize(mWidgetContainer->getWidth() - frameSize,
+ mWidgetContainer->getHeight() - frameSize);
+ if (newScroll)
+ scr->setVerticalScrollAmount(newScroll);
}
}
}
diff --git a/src/gui/widgets/tabs/socialfriendstab.h b/src/gui/widgets/tabs/socialfriendstab.h
index e09068d8d..5f9038f81 100644
--- a/src/gui/widgets/tabs/socialfriendstab.h
+++ b/src/gui/widgets/tabs/socialfriendstab.h
@@ -74,8 +74,6 @@ class SocialFriendsTab final : public SocialTab
return;
std::vector<Avatar*> *const avatars = mBeings->getMembers();
- if (!avatars)
- return;
std::vector<Avatar*>::iterator ia = avatars->begin();
while (ia != avatars->end())
diff --git a/src/gui/widgets/tabs/socialnavigationtab.h b/src/gui/widgets/tabs/socialnavigationtab.h
index b649f2e2a..b4ad01128 100644
--- a/src/gui/widgets/tabs/socialnavigationtab.h
+++ b/src/gui/widgets/tabs/socialnavigationtab.h
@@ -170,7 +170,7 @@ class SocialNavigationTab final : public SocialTab
return;
std::vector<Avatar*> *const avatars = mBeings->getMembers();
- if (!avatars || avatars->size() <= static_cast<size_t>(num))
+ if (avatars->size() <= static_cast<size_t>(num))
return;
const Avatar *const ava = avatars->at(num);
@@ -184,8 +184,6 @@ class SocialNavigationTab final : public SocialTab
return;
std::vector<Avatar*> *const avatars = mBeings->getMembers();
- if (!avatars)
- return;
const Map *const map = socialWindow->getMap();
if (!map)
@@ -220,9 +218,6 @@ class SocialNavigationTab final : public SocialTab
return -1;
std::vector<Avatar*> *const avatars = mBeings->getMembers();
- if (!avatars)
- return -1;
-
const Map *const map = socialWindow->getMap();
if (!map)
return -1;
@@ -255,10 +250,6 @@ class SocialNavigationTab final : public SocialTab
return;
std::vector<Avatar*> *const avatars = mBeings->getMembers();
-
- if (!avatars)
- return;
-
const MapItem *const portal = map->findPortalXY(x, y);
if (!portal)
return;
@@ -288,10 +279,6 @@ class SocialNavigationTab final : public SocialTab
return;
std::vector<Avatar*> *const avatars = mBeings->getMembers();
-
- if (!avatars)
- return;
-
std::vector<Avatar*>::iterator i = avatars->begin();
const std::vector<Avatar*>::iterator i_end = avatars->end();
diff --git a/src/gui/widgets/tabs/socialplayerstab.h b/src/gui/widgets/tabs/socialplayerstab.h
index a7634014b..c0310015f 100644
--- a/src/gui/widgets/tabs/socialplayerstab.h
+++ b/src/gui/widgets/tabs/socialplayerstab.h
@@ -119,9 +119,6 @@ class SocialPlayersTab final : public SocialTab
Avatar* findAvatarbyName(const std::string &name)
{
std::vector<Avatar*> *const avatars = mBeings->getMembers();
- if (!avatars)
- return nullptr;
-
Avatar *ava = nullptr;
std::vector<Avatar*>::const_iterator i = avatars->begin();
const std::vector<Avatar*>::const_iterator i_end = avatars->end();
@@ -141,9 +138,6 @@ class SocialPlayersTab final : public SocialTab
void getPlayersAvatars()
{
std::vector<Avatar*> *const avatars = mBeings->getMembers();
- if (!avatars)
- return;
-
if (actorManager)
{
StringVect names;
diff --git a/src/gui/widgets/tabstrip.cpp b/src/gui/widgets/tabstrip.cpp
index d3f334e8a..025eb7ac7 100644
--- a/src/gui/widgets/tabstrip.cpp
+++ b/src/gui/widgets/tabstrip.cpp
@@ -63,6 +63,8 @@ void TabStrip::action(const ActionEvent &event)
{
Widget *const widget = event.getSource();
Button *const button = static_cast<Button*>(widget);
+ if (!button)
+ return;
if (button->isPressed2())
{
FOR_EACH (WidgetListConstIterator, iter, mWidgets)
diff --git a/src/gui/widgets/widget.h b/src/gui/widgets/widget.h
index c5573b404..840e7ce31 100644
--- a/src/gui/widgets/widget.h
+++ b/src/gui/widgets/widget.h
@@ -682,7 +682,7 @@ class Widget notfinal : public Widget2
* @see setFont, setGlobalFont
* @since 0.1.0
*/
- Font *getFont() const A_WARN_UNUSED;
+ Font *getFont() const RETURNS_NONNULL A_WARN_UNUSED;
/**
* Sets the global font to be used by default for all widgets.
@@ -1027,7 +1027,7 @@ class Widget notfinal : public Widget2
void windowResized();
- static Widget *callPostInit(Widget *const widget);
+ static Widget *callPostInit(Widget *const widget) RETURNS_NONNULL;
virtual void postInit()
{ }
diff --git a/src/gui/widgets/window.cpp b/src/gui/widgets/window.cpp
index 2316af653..73355e3fc 100644
--- a/src/gui/widgets/window.cpp
+++ b/src/gui/widgets/window.cpp
@@ -641,11 +641,14 @@ void Window::widgetResized(const Event &event A_UNUSED)
if (showClose)
{
const Image *const button = mSkin->getCloseImage(false);
- const int buttonWidth = button->getWidth();
- mCloseRect.x = mDimension.width - buttonWidth - mClosePadding;
- mCloseRect.y = mClosePadding;
- mCloseRect.width = buttonWidth;
- mCloseRect.height = button->getHeight();
+ if (button)
+ {
+ const int buttonWidth = button->getWidth();
+ mCloseRect.x = mDimension.width - buttonWidth - mClosePadding;
+ mCloseRect.y = mClosePadding;
+ mCloseRect.width = buttonWidth;
+ mCloseRect.height = button->getHeight();
+ }
}
if (mStickyButton)
{
diff --git a/src/gui/windows/buydialog.cpp b/src/gui/windows/buydialog.cpp
index 3b3657272..84a7a1182 100644
--- a/src/gui/windows/buydialog.cpp
+++ b/src/gui/windows/buydialog.cpp
@@ -488,6 +488,8 @@ void BuyDialog::action(const ActionEvent &event)
else if (eventId == "buy" && mAmountItems > 0 && mAmountItems <= mMaxItems)
{
ShopItem *const item = mShopItems->at(selectedItem);
+ if (!item)
+ return;
if (mNpcId == fromInt(Items, BeingId))
{
adminHandler->createItems(item->getId(),
@@ -544,13 +546,10 @@ void BuyDialog::action(const ActionEvent &event)
if (tradeWindow)
#endif
{
- if (item)
- {
- buySellHandler->sendBuyRequest(mNick,
- item, mAmountItems);
- tradeWindow->addAutoMoney(mNick,
- item->getPrice() * mAmountItems);
- }
+ buySellHandler->sendBuyRequest(mNick,
+ item, mAmountItems);
+ tradeWindow->addAutoMoney(mNick,
+ item->getPrice() * mAmountItems);
}
}
}
diff --git a/src/gui/windows/chatwindow.cpp b/src/gui/windows/chatwindow.cpp
index 3f26cc4dc..f7a101a44 100644
--- a/src/gui/windows/chatwindow.cpp
+++ b/src/gui/windows/chatwindow.cpp
@@ -692,11 +692,11 @@ void ChatWindow::mousePressed(MouseEvent &event)
{
if (popupMenu)
{
- Tab *const tab = mChatTabs->getSelectedTab();
- if (tab)
+ ChatTab *const cTab = dynamic_cast<ChatTab*>(
+ mChatTabs->getSelectedTab());
+ if (cTab)
{
event.consume();
- ChatTab *const cTab = dynamic_cast<ChatTab*>(tab);
if (inputManager.isActionActive(InputAction::CHAT_MOD))
{
inputManager.executeChatCommand(
@@ -2163,11 +2163,14 @@ void ChatWindow::showGMTab()
void ChatWindow::joinRoom(const bool isJoin)
{
Tab *const tab = mChatTabs->getTabByIndex(0);
- std::string name;
- if (isJoin)
- name = PlayerInfo::getRoomName();
- else
- name = _("General");
- tab->setCaption(name);
+ if (tab)
+ {
+ std::string name;
+ if (isJoin)
+ name = PlayerInfo::getRoomName();
+ else
+ name = _("General");
+ tab->setCaption(name);
+ }
}
#endif
diff --git a/src/gui/windows/minimap.cpp b/src/gui/windows/minimap.cpp
index 9e2cb4b81..502ebf91a 100644
--- a/src/gui/windows/minimap.cpp
+++ b/src/gui/windows/minimap.cpp
@@ -393,7 +393,7 @@ void Minimap::draw2(Graphics *const graphics)
const PartyMember *const m = party->getMember(
localPlayer->getName());
const Party::MemberList *const members = party->getMembers();
- if (m && members)
+ if (m)
{
const std::string curMap = m->getMap();
Party::MemberList::const_iterator it = members->begin();
diff --git a/src/gui/windows/skilldialog.cpp b/src/gui/windows/skilldialog.cpp
index 8997220f1..89b614e8d 100644
--- a/src/gui/windows/skilldialog.cpp
+++ b/src/gui/windows/skilldialog.cpp
@@ -337,7 +337,7 @@ void SkillDialog::loadXmlFile(const std::string &fileName)
? 0 : XML::getProperty(node, "level", 0);
SkillData *data = skill->getData(level);
if (!data)
- data = new SkillData();
+ data = new SkillData;
data->name = name;
data->setIcon(icon);
diff --git a/src/gui/windows/statuswindow.cpp b/src/gui/windows/statuswindow.cpp
index ed7438736..5f8df4ef7 100644
--- a/src/gui/windows/statuswindow.cpp
+++ b/src/gui/windows/statuswindow.cpp
@@ -633,7 +633,7 @@ std::string StatusWindow::translateLetter(const char *const letters)
{
char buf[2];
char *const str = gettext(letters);
- if (strlen(str) != 3)
+ if (!str || strlen(str) != 3)
return letters;
buf[0] = str[1];
diff --git a/src/gui/windows/textdialog.cpp b/src/gui/windows/textdialog.cpp
index 642d574cc..0d74c95e5 100644
--- a/src/gui/windows/textdialog.cpp
+++ b/src/gui/windows/textdialog.cpp
@@ -68,18 +68,10 @@ TextDialog::TextDialog(const std::string &restrict title,
place(2, 2, mOkButton);
place(3, 2, cancelButton);
- const Font *const font = getFont();
- if (font)
- {
- int width = font->getWidth(title);
- if (width < textLabel->getWidth())
- width = textLabel->getWidth();
- reflowLayout(static_cast<int>(width + 20));
- }
- else
- {
- reflowLayout(static_cast<int>(textLabel->getWidth() + 20));
- }
+ int width = getFont()->getWidth(title);
+ if (width < textLabel->getWidth())
+ width = textLabel->getWidth();
+ reflowLayout(static_cast<int>(width + 20));
}
void TextDialog::postInit()