Skip to content

Commit 576b44d

Browse files
committed
🐛 Wipe cached LoaderData when stores are changed
refs #35
1 parent 89deb96 commit 576b44d

File tree

2 files changed

+19
-8
lines changed

2 files changed

+19
-8
lines changed

src/windows/WindowsPlatform.cpp

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -208,11 +208,16 @@ void WindowsPlatform::MainLoop(const std::function<void()>& drawFrame) {
208208

209209
const wil::unique_event changeEvent(
210210
CreateEventW(nullptr, FALSE, TRUE, nullptr));
211-
const auto changeSubscriptions
212-
= APILayerStore::Get()
213-
| std::views::transform([e = changeEvent.get()](const auto store) {
214-
return store->OnChange(std::bind_front(&SetEvent, e));
215-
})
211+
const auto changeSubscriptions = APILayerStore::Get()
212+
| std::views::transform([e = changeEvent.get(), this](const auto store) {
213+
return store->OnChange([e, this] {
214+
{
215+
const std::unique_lock lock(mMutex);
216+
mLoaderData.reset();
217+
}
218+
SetEvent(e);
219+
});
220+
})
216221
| std::ranges::to<std::vector>();
217222

218223
while (true) {
@@ -229,9 +234,12 @@ void WindowsPlatform::MainLoop(const std::function<void()>& drawFrame) {
229234

230235
ResetEvent(changeEvent.get());
231236

232-
this->BeforeFrame();
233-
drawFrame();
234-
this->AfterFrame();
237+
{
238+
const std::unique_lock lock(mMutex);
239+
this->BeforeFrame();
240+
drawFrame();
241+
this->AfterFrame();
242+
}
235243

236244
{
237245
const auto e = changeEvent.get();

src/windows/WindowsPlatform.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
#include <wil/com.h>
66
#include <wil/resource.h>
77

8+
#include <mutex>
9+
810
#include <d3d11.h>
911
#include <dxgi1_2.h>
1012

@@ -58,6 +60,7 @@ class WindowsPlatform final : public Platform {
5860
Config::MINIMUM_WINDOW_WIDTH,
5961
Config::MINIMUM_WINDOW_HEIGHT,
6062
};
63+
std::mutex mMutex;
6164
std::optional<std::expected<LoaderData, LoaderData::Error>> mLoaderData;
6265

6366
HWND CreateAppWindow();

0 commit comments

Comments
 (0)