Sdk/BaseWidget: Fix crash at Canvas destruction
This commit is contained in:
parent
d57498be10
commit
6acf101d77
|
|
@ -5,10 +5,12 @@
|
|||
#include <NDK/BaseWidget.hpp>
|
||||
#include <Nazara/Core/Error.hpp>
|
||||
#include <Nazara/Math/Algorithm.hpp>
|
||||
#include <limits>
|
||||
|
||||
namespace Ndk
|
||||
{
|
||||
inline BaseWidget::BaseWidget() :
|
||||
m_canvasIndex(std::numeric_limits<std::size_t>::max()),
|
||||
m_backgroundColor(Nz::Color(230, 230, 230, 255)),
|
||||
m_canvas(nullptr),
|
||||
m_contentSize(50.f, 50.f),
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
Loading…
Reference in New Issue