// This file is part of the FidelityFX SDK.1//2// Copyright (c) 2022-2023 Advanced Micro Devices, Inc. All rights reserved.3//4// Permission is hereby granted, free of charge, to any person obtaining a copy5// of this software and associated documentation files (the "Software"), to deal6// in the Software without restriction, including without limitation the rights7// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell8// copies of the Software, and to permit persons to whom the Software is9// furnished to do so, subject to the following conditions:10// The above copyright notice and this permission notice shall be included in11// all copies or substantial portions of the Software.12//13// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR14// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,15// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE16// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER17// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,18// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN19// THE SOFTWARE.2021#include "ffx_assert.h"22#include <stdlib.h> // for malloc()2324#ifdef _WIN3225#ifndef WIN32_LEAN_AND_MEAN26#define WIN32_LEAN_AND_MEAN27#endif28#include <windows.h> // required for OutputDebugString()29#include <stdio.h> // required for sprintf_s30#endif // #ifndef _WIN323132static FfxAssertCallback s_assertCallback;3334// set the printing callback function35void ffxAssertSetPrintingCallback(FfxAssertCallback callback)36{37s_assertCallback = callback;38return;39}4041// implementation of assert reporting42bool ffxAssertReport(const char* file, int32_t line, const char* condition, const char* message)43{44if (!file) {4546return true;47}4849#ifdef _WIN3250// form the final assertion string and output to the TTY.51const size_t bufferSize = static_cast<size_t>(snprintf(nullptr, 0, "%s(%d): ASSERTION FAILED. %s\n", file, line, message ? message : condition)) + 1;52char* tempBuf = static_cast<char*>(malloc(bufferSize));53if (!tempBuf) {5455return true;56}5758if (!message) {59sprintf_s(tempBuf, bufferSize, "%s(%d): ASSERTION FAILED. %s\n", file, line, condition);60} else {61sprintf_s(tempBuf, bufferSize, "%s(%d): ASSERTION FAILED. %s\n", file, line, message);62}6364if (!s_assertCallback) {65OutputDebugStringA(tempBuf);66} else {67s_assertCallback(tempBuf);68}6970// free the buffer.71free(tempBuf);7273#else74FFX_UNUSED(line);75FFX_UNUSED(condition);76FFX_UNUSED(message);77#endif7879return true;80}818283