Skip to content

Commit

Permalink
Make gui2::event::message noncopyable
Browse files Browse the repository at this point in the history
This makes it impossible to accidentally pass a message by value, which
avoids problems like the crashes @Vultraz got when refactoring the event
dispatcher.
  • Loading branch information
jyrkive committed Apr 30, 2017
1 parent 076c47c commit 804c7d6
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
3 changes: 1 addition & 2 deletions src/gui/core/event/dispatcher.cpp
Expand Up @@ -174,8 +174,7 @@ bool dispatcher::fire(const ui_event event, widget& target, void*)
bool dispatcher::fire(const ui_event event, widget& target, message& msg)
{
assert(find<set_event_message>(event, event_in_set()));
// NOTE: std::ref() needed here to prevent reference decay.
return fire_event<signal_message_function>(event, this, &target, std::ref(msg));
return fire_event<signal_message_function>(event, this, &target, msg);
}

void dispatcher::register_hotkey(const hotkey::HOTKEY_COMMAND id, const thotkey_function& function)
Expand Down
5 changes: 5 additions & 0 deletions src/gui/core/event/message.hpp
Expand Up @@ -46,6 +46,11 @@ namespace event
*/
struct message
{
message() = default;

// Disallow copying because constructing a copy loses the exact type.
message(const message&) = delete;

virtual ~message()
{
}
Expand Down

0 comments on commit 804c7d6

Please sign in to comment.