Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: avoid potential crash when layout is not created yet #692

Merged
merged 1 commit into from
Jan 3, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions src/client/uiminimap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ bool UIMinimap::setZoom(int8_t zoom)
else if (m_zoom > 0)
m_scale *= 1 << std::abs(zoom);

m_layout->update();
if (m_layout)
m_layout->update();

onZoomChange(zoom, oldZoom);
return true;
Expand All @@ -70,7 +71,9 @@ void UIMinimap::setCameraPosition(const Position& pos)

const Position oldPos = m_cameraPosition;
m_cameraPosition = pos;
m_layout->update();

if (m_layout)
m_layout->update();

onCameraPositionChange(pos, oldPos);
}
Expand Down Expand Up @@ -111,20 +114,29 @@ Position UIMinimap::getTilePosition(const Point& mousePos)

void UIMinimap::anchorPosition(const UIWidgetPtr& anchoredWidget, Fw::AnchorEdge anchoredEdge, const Position& hookedPosition, Fw::AnchorEdge hookedEdge)
{
if(!m_layout)
return;

const auto& layout = m_layout->static_self_cast<UIMapAnchorLayout>();
assert(layout);
layout->addPositionAnchor(anchoredWidget, anchoredEdge, hookedPosition, hookedEdge);
}

void UIMinimap::fillPosition(const UIWidgetPtr& anchoredWidget, const Position& hookedPosition)
{
if(!m_layout)
return;

const auto& layout = m_layout->static_self_cast<UIMapAnchorLayout>();
assert(layout);
layout->fillPosition(anchoredWidget, hookedPosition);
}

void UIMinimap::centerInPosition(const UIWidgetPtr& anchoredWidget, const Position& hookedPosition)
{
if(!m_layout)
return;

const auto& layout = m_layout->static_self_cast<UIMapAnchorLayout>();
assert(layout);
layout->centerInPosition(anchoredWidget, hookedPosition);
Expand Down
Loading