Improve Optick error reporting to debugger and to console stderr for all platforms

This commit is contained in:
SRSaunders 2024-02-20 17:15:10 -05:00
parent 7183e8707b
commit 0e29370423
2 changed files with 18 additions and 9 deletions

View file

@ -29,6 +29,7 @@
#include "optick.h"
#include <cstdio>
#include <iostream>
#include <stdarg.h>
#include <stddef.h>
#include <stdint.h>
@ -134,21 +135,29 @@ static const ProcessID INVALID_PROCESS_ID = (ProcessID)-1;
// Asserts
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
#if defined(OPTICK_MSVC)
#define OPTICK_DEBUG_BREAK __debugbreak()
#ifdef UNICODE
#define OPTICK_DEBUG_BREAK(description) OutputDebugString(L"Optick ERROR: " description L"\n"); __debugbreak()
#else
#define OPTICK_DEBUG_BREAK(description) OutputDebugString("Optick ERROR: " description "\n"); __debugbreak()
#endif
#elif defined(OPTICK_GCC)
#define OPTICK_DEBUG_BREAK __builtin_trap()
#if __has_builtin(__builtin_debugtrap)
#define OPTICK_DEBUG_BREAK(description) std::cerr << "Optick ERROR: " << description << std::endl; __builtin_debugtrap()
#else
#define OPTICK_DEBUG_BREAK(description) std::cerr << "Optick ERROR: " << description << std::endl; __builtin_trap()
#endif
#else
#error Can not define OPTICK_DEBUG_BREAK. Unknown platform.
#endif
#define OPTICK_UNUSED(x) (void)(x)
#ifdef _DEBUG
#define OPTICK_ASSERT(arg, description) if (!(arg)) { OPTICK_DEBUG_BREAK; }
#define OPTICK_FAILED(description) { OPTICK_DEBUG_BREAK; }
#define OPTICK_VERIFY(arg, description, operation) if (!(arg)) { OPTICK_DEBUG_BREAK; operation; }
#define OPTICK_ASSERT(arg, description) if (!(arg)) { OPTICK_DEBUG_BREAK(description); }
#define OPTICK_FAILED(description) { OPTICK_DEBUG_BREAK(description); }
#define OPTICK_VERIFY(arg, description, operation) if (!(arg)) { OPTICK_DEBUG_BREAK(description); operation; }
#else
#define OPTICK_ASSERT(arg, description)
#define OPTICK_FAILED(description) { throw std::runtime_error(description); }
#define OPTICK_VERIFY(arg, description, operation) if (!(arg)) { printf("%s\n", description); operation; }
#define OPTICK_FAILED(description) { std::cerr << "Optick FATAL ERROR: " << description << std::endl; throw std::runtime_error("Optick FAILED"); }
#define OPTICK_VERIFY(arg, description, operation) if (!(arg)) { std::cerr << "Optick ERROR: " << description << std::endl; operation; }
#endif
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

View file

@ -241,7 +241,7 @@ public:
return true;
}
#if defined(_WIN32)
#if defined(USE_WINDOWS_SOCKETS)
int Receive(char *buf, int len)
#else
ssize_t Receive(char *buf, int len)
@ -308,7 +308,7 @@ void Server::Update()
if (!InitConnection())
return;
#if defined(_WIN32)
#if defined(USE_WINDOWS_SOCKETS)
int length = -1;
#else
ssize_t length = -1;