Skip to content

Commit

Permalink
Use proper capturing technique.
Browse files Browse the repository at this point in the history
  • Loading branch information
Themaister committed Nov 19, 2023
1 parent 95de1ab commit a7ebfc6
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
7 changes: 4 additions & 3 deletions application/events/application_wsi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,15 +98,15 @@ void GraniteWSIPlatform::dispatch_template_filter(const T &t)
}

template <typename Func>
void GraniteWSIPlatform::dispatch_or_defer(const Func &func)
void GraniteWSIPlatform::dispatch_or_defer(Func &&func)
{
if (in_async_input)
captured.emplace_back(std::move(func));
captured.emplace_back(std::forward<Func>(func));
else
func();
}

#define WORK(work) dispatch_or_defer([this, &e]() { work; })
#define WORK(work) dispatch_or_defer([this, e]() { work; })

void GraniteWSIPlatform::dispatch(const TouchDownEvent &e)
{
Expand Down Expand Up @@ -180,6 +180,7 @@ void GraniteWSIPlatform::end_async_input_handling()

void GraniteWSIPlatform::flush_deferred_input_events()
{
VK_ASSERT(!in_async_input);
for (auto &func : captured)
func();
captured.clear();
Expand Down
2 changes: 1 addition & 1 deletion application/events/application_wsi.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ class GraniteWSIPlatform : public Vulkan::WSIPlatform, private InputTrackerHandl
template <typename T>
void dispatch_template(const T &t);
template <typename Func>
void dispatch_or_defer(const Func &func);
void dispatch_or_defer(Func &&func);

bool in_async_input = false;
std::vector<std::function<void ()>> captured;
Expand Down

0 comments on commit a7ebfc6

Please sign in to comment.