Sdk/BaseWidget: Fix crash at Canvas destruction

This commit is contained in:
Lynix
2017-01-11 19:14:21 +01:00
parent d57498be10
commit 6acf101d77
3 changed files with 14 additions and 9 deletions

View File

@@ -25,7 +25,8 @@ namespace Ndk
BaseWidget::~BaseWidget()
{
m_canvas->UnregisterWidget(m_canvasIndex);
if (m_canvasIndex != std::numeric_limits<std::size_t>::max())
m_canvas->UnregisterWidget(m_canvasIndex);
}
inline void BaseWidget::EnableBackground(bool enable)

View File

@@ -49,21 +49,23 @@ namespace Ndk
void Canvas::UnregisterWidget(std::size_t index)
{
WidgetBox& entry = m_widgetBoxes[index];
if (m_hoveredWidget == &entry)
m_hoveredWidget = nullptr;
if (m_keyboardOwner == entry.widget)
m_keyboardOwner = nullptr;
if (m_widgetBoxes.size() > 1U)
{
WidgetBox& entry = m_widgetBoxes[index];
WidgetBox& lastEntry = m_widgetBoxes.back();
if (m_hoveredWidget == &entry)
m_hoveredWidget = nullptr;
if (m_keyboardOwner == entry.widget)
m_keyboardOwner = nullptr;
entry = std::move(lastEntry);
entry.widget->UpdateCanvasIndex(index);
m_widgetBoxes.pop_back();
}
m_widgetBoxes.pop_back();
}
void Canvas::OnMouseButtonPressed(const Nz::EventHandler* /*eventHandler*/, const Nz::WindowEvent::MouseButtonEvent& event)