From 41c627fd420a644f0ae86e36f4752e820e2d683c Mon Sep 17 00:00:00 2001 From: Anders Leino Date: Wed, 18 Dec 2024 14:39:17 +0200 Subject: Add slang example tests to CI (#5879) * Examples: Don't proceed if 'initializeBase' fails * Examples: Only access gWindow if it's been initialized * Examples: Free memory from CommandLineToArgvW * Add example run step to CI Lots of examples are still unexpectedly failing, but is one small step towards addressing issue #5520. --- examples/shader-toy/main.cpp | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) (limited to 'examples/shader-toy/main.cpp') diff --git a/examples/shader-toy/main.cpp b/examples/shader-toy/main.cpp index 1ab85c0b2..185d18246 100644 --- a/examples/shader-toy/main.cpp +++ b/examples/shader-toy/main.cpp @@ -282,10 +282,18 @@ struct ShaderToyApp : public WindowedAppBase Result initialize() { - initializeBase("Shader Toy", 1024, 768); - gWindow->events.mouseMove = [this](const platform::MouseEventArgs& e) { handleEvent(e); }; - gWindow->events.mouseUp = [this](const platform::MouseEventArgs& e) { handleEvent(e); }; - gWindow->events.mouseDown = [this](const platform::MouseEventArgs& e) { handleEvent(e); }; + SLANG_RETURN_ON_FAIL(initializeBase("Shader Toy", 1024, 768)); + + // We may not have a window if we're running in test mode + SLANG_ASSERT(isTestMode() || gWindow); + if (gWindow) + { + gWindow->events.mouseMove = [this](const platform::MouseEventArgs& e) + { handleEvent(e); }; + gWindow->events.mouseUp = [this](const platform::MouseEventArgs& e) { handleEvent(e); }; + gWindow->events.mouseDown = [this](const platform::MouseEventArgs& e) + { handleEvent(e); }; + } InputElementDesc inputElements[] = { {"POSITION", 0, Format::R32G32_FLOAT, offsetof(FullScreenTriangle::Vertex, position)}, @@ -383,7 +391,11 @@ struct ShaderToyApp : public WindowedAppBase commandBuffer->close(); gQueue->executeCommandBuffer(commandBuffer); - gSwapchain->present(); + + // We may not have a swapchain if we're running in test mode + SLANG_ASSERT(isTestMode() || gSwapchain); + if (gSwapchain) + gSwapchain->present(); } void handleEvent(const platform::MouseEventArgs& event) -- cgit v1.2.3