[WGPUFutures] Correct loop condition for wait polling.
Bug: dawn:2460
Change-Id: I7222d7d8809fbc9884ecc3c886d175259c8a087e
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/178881
Reviewed-by: Austin Eng <enga@chromium.org>
Commit-Queue: Loko Kung <lokokung@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
diff --git a/src/dawn/native/EventManager.cpp b/src/dawn/native/EventManager.cpp
index 2e85fdd..7037557 100644
--- a/src/dawn/native/EventManager.cpp
+++ b/src/dawn/native/EventManager.cpp
@@ -263,7 +263,7 @@
} else {
// Poll the completion events.
success = false;
- for (auto it = begin; it != end; ++it) {
+ for (auto it = begin; it != mid; ++it) {
if (std::get<Ref<SystemEvent>>(it->event->GetCompletionData())->IsSignaled()) {
it->ready = true;
success = true;
diff --git a/src/dawn/tests/end2end/EventTests.cpp b/src/dawn/tests/end2end/EventTests.cpp
index f05939c..30acd1c 100644
--- a/src/dawn/tests/end2end/EventTests.cpp
+++ b/src/dawn/tests/end2end/EventTests.cpp
@@ -633,5 +633,31 @@
OpenGLBackend(),
OpenGLESBackend());
+class FutureTests : public DawnTest {};
+
+// Regression test for crbug.com/dawn/2460 where when we have mixed source futures in a process
+// events call we were crashing.
+TEST_P(FutureTests, MixedSourcePolling) {
+ // OnSubmittedWorkDone is implemented via a queue serial.
+ device.GetQueue().OnSubmittedWorkDone({nullptr, wgpu::CallbackMode::AllowProcessEvents,
+ [](WGPUQueueWorkDoneStatus, void*) {}, nullptr});
+
+ // PopErrorScope is implemented via a signal.
+ device.PushErrorScope(wgpu::ErrorFilter::Validation);
+ device.PopErrorScope({nullptr, wgpu::CallbackMode::AllowProcessEvents,
+ [](WGPUPopErrorScopeStatus, WGPUErrorType, char const*, void*) {},
+ nullptr, nullptr});
+
+ instance.ProcessEvents();
+}
+
+DAWN_INSTANTIATE_TEST(FutureTests,
+ D3D11Backend(),
+ D3D12Backend(),
+ MetalBackend(),
+ VulkanBackend(),
+ OpenGLBackend(),
+ OpenGLESBackend());
+
} // anonymous namespace
} // namespace dawn