mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 15:47:44 +00:00
WindowServer: Make WSButton a Weakable and stop rawly pointing to it.
We had a crash due to dereferencing a destroyed WSButton after clicking a window close button. Avoid that problem by using WeakPtr.
This commit is contained in:
parent
e74f32ae40
commit
0808d5158c
3 changed files with 11 additions and 5 deletions
|
@ -3,13 +3,14 @@
|
||||||
#include <SharedGraphics/Rect.h>
|
#include <SharedGraphics/Rect.h>
|
||||||
#include <AK/Function.h>
|
#include <AK/Function.h>
|
||||||
#include <AK/Retained.h>
|
#include <AK/Retained.h>
|
||||||
|
#include <AK/Weakable.h>
|
||||||
|
|
||||||
class CharacterBitmap;
|
class CharacterBitmap;
|
||||||
class Painter;
|
class Painter;
|
||||||
class WSMouseEvent;
|
class WSMouseEvent;
|
||||||
class WSWindowFrame;
|
class WSWindowFrame;
|
||||||
|
|
||||||
class WSButton final {
|
class WSButton : public Weakable<WSButton> {
|
||||||
public:
|
public:
|
||||||
WSButton(WSWindowFrame&, Retained<CharacterBitmap>&&, Function<void()>&& on_click_handler);
|
WSButton(WSWindowFrame&, Retained<CharacterBitmap>&&, Function<void()>&& on_click_handler);
|
||||||
~WSButton();
|
~WSButton();
|
||||||
|
|
|
@ -621,6 +621,11 @@ bool WSWindowManager::process_ongoing_window_resize(const WSMouseEvent& event, W
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void WSWindowManager::set_cursor_tracking_button(WSButton* button)
|
||||||
|
{
|
||||||
|
m_cursor_tracking_button = button ? button->make_weak_ptr() : nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
void WSWindowManager::process_mouse_event(const WSMouseEvent& event, WSWindow*& event_window)
|
void WSWindowManager::process_mouse_event(const WSMouseEvent& event, WSWindow*& event_window)
|
||||||
{
|
{
|
||||||
event_window = nullptr;
|
event_window = nullptr;
|
||||||
|
@ -1117,5 +1122,5 @@ const WSCursor& WSWindowManager::active_cursor() const
|
||||||
|
|
||||||
void WSWindowManager::set_hovered_button(WSButton* button)
|
void WSWindowManager::set_hovered_button(WSButton* button)
|
||||||
{
|
{
|
||||||
m_hovered_button = button;
|
m_hovered_button = button ? button->make_weak_ptr() : nullptr;
|
||||||
}
|
}
|
||||||
|
|
|
@ -100,7 +100,7 @@ public:
|
||||||
const WSCursor& move_cursor() const { return *m_move_cursor; }
|
const WSCursor& move_cursor() const { return *m_move_cursor; }
|
||||||
|
|
||||||
void set_active_window(WSWindow*);
|
void set_active_window(WSWindow*);
|
||||||
void set_cursor_tracking_button(WSButton* button) { m_cursor_tracking_button = button; }
|
void set_cursor_tracking_button(WSButton*);
|
||||||
void set_hovered_button(WSButton*);
|
void set_hovered_button(WSButton*);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -207,8 +207,8 @@ private:
|
||||||
CircularQueue<float, 30> m_cpu_history;
|
CircularQueue<float, 30> m_cpu_history;
|
||||||
|
|
||||||
String m_username;
|
String m_username;
|
||||||
WSButton* m_cursor_tracking_button { nullptr };
|
WeakPtr<WSButton> m_cursor_tracking_button;
|
||||||
WSButton* m_hovered_button { nullptr };
|
WeakPtr<WSButton> m_hovered_button;
|
||||||
};
|
};
|
||||||
|
|
||||||
template<typename Callback>
|
template<typename Callback>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue