Added file/line argument to fatal callback.

This commit is contained in:
Branimir Karadžić 2018-09-19 17:54:51 -07:00
parent 7ed47a3507
commit 99e6da5b50
12 changed files with 57 additions and 48 deletions

View File

@ -829,7 +829,7 @@ void ImDrawList::AddConvexPolyFilled(const ImVec2* points, const int points_coun
// Anti-aliased Fill // Anti-aliased Fill
const float AA_SIZE = 1.0f; const float AA_SIZE = 1.0f;
const ImU32 col_trans = col & ~IM_COL32_A_MASK; const ImU32 col_trans = col & ~IM_COL32_A_MASK;
const int idx_count = (points_count-2)*3 + points_count*6; const int idx_count = ImMax(0, (points_count-2)*3) + points_count*6;
const int vtx_count = (points_count*2); const int vtx_count = (points_count*2);
PrimReserve(idx_count, vtx_count); PrimReserve(idx_count, vtx_count);

View File

@ -97,8 +97,10 @@ struct BgfxCallback : public bgfx::CallbackI
{ {
} }
virtual void fatal(bgfx::Fatal::Enum _code, const char* _str) override virtual void fatal(const char* _filePath, uint16_t _line, bgfx::Fatal::Enum _code, const char* _str) override
{ {
BX_UNUSED(_filePath, _line);
// Something unexpected happened, inform user and bail out. // Something unexpected happened, inform user and bail out.
bx::debugPrintf("Fatal error: 0x%08x: %s", _code, _str); bx::debugPrintf("Fatal error: 0x%08x: %s", _code, _str);

View File

@ -430,7 +430,12 @@ namespace bgfx
/// ///
/// @attention C99 equivalent is `bgfx_callback_vtbl.fatal`. /// @attention C99 equivalent is `bgfx_callback_vtbl.fatal`.
/// ///
virtual void fatal(Fatal::Enum _code, const char* _str) = 0; virtual void fatal(
const char* _filePath
, uint16_t _line
, Fatal::Enum _code
, const char* _str
) = 0;
/// Print debug message. /// Print debug message.
/// ///

View File

@ -567,7 +567,7 @@ typedef struct bgfx_callback_interface_s
/**/ /**/
typedef struct bgfx_callback_vtbl_s typedef struct bgfx_callback_vtbl_s
{ {
void (*fatal)(bgfx_callback_interface_t* _this, bgfx_fatal_t _code, const char* _str); void (*fatal)(bgfx_callback_interface_t* _this, const char* _filePath, uint16_t _line, bgfx_fatal_t _code, const char* _str);
void (*trace_vargs)(bgfx_callback_interface_t* _this, const char* _filePath, uint16_t _line, const char* _format, va_list _argList); void (*trace_vargs)(bgfx_callback_interface_t* _this, const char* _filePath, uint16_t _line, const char* _format, va_list _argList);
void (*profiler_begin)(bgfx_callback_interface_t* _this, const char* _name, uint32_t _abgr, const char* _filePath, uint16_t _line); void (*profiler_begin)(bgfx_callback_interface_t* _this, const char* _name, uint32_t _abgr, const char* _filePath, uint16_t _line);
void (*profiler_begin_literal)(bgfx_callback_interface_t* _this, const char* _name, uint32_t _abgr, const char* _filePath, uint16_t _line); void (*profiler_begin_literal)(bgfx_callback_interface_t* _this, const char* _name, uint32_t _abgr, const char* _filePath, uint16_t _line);

View File

@ -6,7 +6,7 @@
#ifndef BGFX_DEFINES_H_HEADER_GUARD #ifndef BGFX_DEFINES_H_HEADER_GUARD
#define BGFX_DEFINES_H_HEADER_GUARD #define BGFX_DEFINES_H_HEADER_GUARD
#define BGFX_API_VERSION UINT32_C(82) #define BGFX_API_VERSION UINT32_C(83)
/// Color RGB/alpha/depth write. When it's not specified write will be disabled. /// Color RGB/alpha/depth write. When it's not specified write will be disabled.
#define BGFX_STATE_WRITE_R UINT64_C(0x0000000000000001) //!< Enable R write. #define BGFX_STATE_WRITE_R UINT64_C(0x0000000000000001) //!< Enable R write.

View File

@ -54,7 +54,7 @@ namespace bgfx
{ {
} }
virtual void fatal(Fatal::Enum _code, const char* _str) override virtual void fatal(const char* _filePath, uint16_t _line, Fatal::Enum _code, const char* _str) override
{ {
if (Fatal::DebugCheck == _code) if (Fatal::DebugCheck == _code)
{ {
@ -62,7 +62,7 @@ namespace bgfx
} }
else else
{ {
BX_TRACE("0x%08x: %s", _code, _str); bgfx::trace(_filePath, _line, "BGFX 0x%08x: %s\n", _code, _str);
BX_UNUSED(_code, _str); BX_UNUSED(_code, _str);
abort(); abort();
} }
@ -387,29 +387,29 @@ namespace bgfx
return s_graphicsDebuggerPresent; return s_graphicsDebuggerPresent;
} }
void fatal(Fatal::Enum _code, const char* _format, ...) void fatal(const char* _filePath, uint16_t _line, Fatal::Enum _code, const char* _format, ...)
{ {
va_list argList; va_list argList;
va_start(argList, _format); va_start(argList, _format);
char temp[8192];
char* out = temp;
int32_t len = bx::vsnprintf(out, sizeof(temp), _format, argList);
if ( (int32_t)sizeof(temp) < len)
{
out = (char*)alloca(len+1);
len = bx::vsnprintf(out, len, _format, argList);
}
out[len] = '\0';
if (BX_UNLIKELY(NULL == g_callback) ) if (BX_UNLIKELY(NULL == g_callback) )
{ {
bx::debugPrintfVargs(_format, argList); bx::debugPrintf("%s(%d): BGFX 0x%08x: %s", _filePath, _line, _code, out);
abort(); abort();
} }
else else
{ {
char temp[8192]; g_callback->fatal(_filePath, _line, _code, out);
char* out = temp;
int32_t len = bx::vsnprintf(out, sizeof(temp), _format, argList);
if ( (int32_t)sizeof(temp) < len)
{
out = (char*)alloca(len+1);
len = bx::vsnprintf(out, len, _format, argList);
}
out[len] = '\0';
g_callback->fatal(_code, out);
} }
va_end(argList); va_end(argList);
@ -4684,9 +4684,9 @@ namespace bgfx
{ {
} }
virtual void fatal(Fatal::Enum _code, const char* _str) override virtual void fatal(const char* _filePath, uint16_t _line, Fatal::Enum _code, const char* _str) override
{ {
m_interface->vtbl->fatal(m_interface, (bgfx_fatal_t)_code, _str); m_interface->vtbl->fatal(m_interface, _filePath, _line, (bgfx_fatal_t)_code, _str);
} }
virtual void traceVargs(const char* _filePath, uint16_t _line, const char* _format, va_list _argList) override virtual void traceVargs(const char* _filePath, uint16_t _line, const char* _format, va_list _argList) override

View File

@ -67,7 +67,7 @@ namespace bgfx
#if BX_COMPILER_CLANG_ANALYZER #if BX_COMPILER_CLANG_ANALYZER
void __attribute__( (analyzer_noreturn) ) fatal(Fatal::Enum _code, const char* _format, ...); void __attribute__( (analyzer_noreturn) ) fatal(Fatal::Enum _code, const char* _format, ...);
#else #else
void fatal(Fatal::Enum _code, const char* _format, ...); void fatal(const char* _filePath, uint16_t _line, Fatal::Enum _code, const char* _format, ...);
#endif // BX_COMPILER_CLANG_ANALYZER #endif // BX_COMPILER_CLANG_ANALYZER
void trace(const char* _filePath, uint16_t _line, const char* _format, ...); void trace(const char* _filePath, uint16_t _line, const char* _format, ...);
@ -89,21 +89,21 @@ namespace bgfx
} \ } \
BX_MACRO_BLOCK_END BX_MACRO_BLOCK_END
#define _BX_CHECK(_condition, _format, ...) \ #define _BX_CHECK(_condition, _format, ...) \
BX_MACRO_BLOCK_BEGIN \ BX_MACRO_BLOCK_BEGIN \
if (!BX_IGNORE_C4127(_condition) ) \ if (!BX_IGNORE_C4127(_condition) ) \
{ \ { \
BX_TRACE("CHECK " _format, ##__VA_ARGS__); \ BX_TRACE("CHECK " _format, ##__VA_ARGS__); \
bgfx::fatal(bgfx::Fatal::DebugCheck, _format, ##__VA_ARGS__); \ bgfx::fatal(__FILE__, uint16_t(__LINE__), bgfx::Fatal::DebugCheck, _format, ##__VA_ARGS__); \
} \ } \
BX_MACRO_BLOCK_END BX_MACRO_BLOCK_END
#define BGFX_FATAL(_condition, _err, _format, ...) \ #define BGFX_FATAL(_condition, _err, _format, ...) \
BX_MACRO_BLOCK_BEGIN \ BX_MACRO_BLOCK_BEGIN \
if (!BX_IGNORE_C4127(_condition) ) \ if (!BX_IGNORE_C4127(_condition) ) \
{ \ { \
fatal(_err, _format, ##__VA_ARGS__); \ fatal(__FILE__, uint16_t(__LINE__), _err, _format, ##__VA_ARGS__); \
} \ } \
BX_MACRO_BLOCK_END BX_MACRO_BLOCK_END
#include <bx/allocator.h> #include <bx/allocator.h>

View File

@ -288,7 +288,7 @@ namespace bgfx
} }
// BK - warn only because RenderDoc might be present. // BK - warn only because RenderDoc might be present.
DX_RELEASE_WARNONLY(output6, 1); DX_RELEASE_W(output6, 1);
} }
#endif // BX_PLATFORM_WINDOWS #endif // BX_PLATFORM_WINDOWS
@ -358,7 +358,7 @@ namespace bgfx
DX_CHECK(m_adapter->GetParent(IID_IDXGIFactory2, (void**)&m_factory) ); DX_CHECK(m_adapter->GetParent(IID_IDXGIFactory2, (void**)&m_factory) );
} }
DX_RELEASE(dxgiDevice, 2); DX_RELEASE_I(dxgiDevice);
} }
static const GUID IID_ID3D12CommandQueue = { 0x0ec870a6, 0x5d7e, 0x4c22, { 0x8c, 0xfc, 0x5b, 0xaa, 0xe0, 0x76, 0x16, 0xed } }; static const GUID IID_ID3D12CommandQueue = { 0x0ec870a6, 0x5d7e, 0x4c22, { 0x8c, 0xfc, 0x5b, 0xaa, 0xe0, 0x76, 0x16, 0xed } };
@ -411,7 +411,7 @@ namespace bgfx
if (NULL != dxgiDevice1) if (NULL != dxgiDevice1)
{ {
dxgiDevice1->SetMaximumFrameLatency(_scd.maxFrameLatency); dxgiDevice1->SetMaximumFrameLatency(_scd.maxFrameLatency);
DX_RELEASE(dxgiDevice1, 3); DX_RELEASE_I(dxgiDevice1);
} }
} }
#else #else

View File

@ -122,7 +122,8 @@ namespace bgfx
#endif // BGFX_CONFIG_DEBUG_OBJECT_NAME #endif // BGFX_CONFIG_DEBUG_OBJECT_NAME
#define DX_RELEASE(_ptr, _expected) _DX_RELEASE(_ptr, _expected, BX_CHECK) #define DX_RELEASE(_ptr, _expected) _DX_RELEASE(_ptr, _expected, BX_CHECK)
#define DX_RELEASE_WARNONLY(_ptr, _expected) _DX_RELEASE(_ptr, _expected, BX_WARN) #define DX_RELEASE_W(_ptr, _expected) _DX_RELEASE(_ptr, _expected, BX_WARN)
#define DX_RELEASE_I(_ptr) _DX_RELEASE(_ptr, 0, BX_NOOP)
typedef int (WINAPI* PFN_D3DPERF_BEGIN_EVENT)(DWORD _color, LPCWSTR _name); typedef int (WINAPI* PFN_D3DPERF_BEGIN_EVENT)(DWORD _color, LPCWSTR _name);
typedef int (WINAPI* PFN_D3DPERF_END_EVENT)(); typedef int (WINAPI* PFN_D3DPERF_END_EVENT)();
@ -204,7 +205,7 @@ namespace bgfx
typename HashMap::iterator it = m_hashMap.find(_key); typename HashMap::iterator it = m_hashMap.find(_key);
if (it != m_hashMap.end() ) if (it != m_hashMap.end() )
{ {
DX_RELEASE_WARNONLY(it->second, 0); DX_RELEASE_W(it->second, 0);
m_hashMap.erase(it); m_hashMap.erase(it);
} }
} }

View File

@ -1524,7 +1524,7 @@ namespace bgfx { namespace d3d11
{ {
case ErrorState::LoadedDXGI: case ErrorState::LoadedDXGI:
DX_RELEASE(m_annotation, 1); DX_RELEASE(m_annotation, 1);
DX_RELEASE_WARNONLY(m_infoQueue, 0); DX_RELEASE_W(m_infoQueue, 0);
DX_RELEASE(m_msaaRt, 0); DX_RELEASE(m_msaaRt, 0);
DX_RELEASE(m_swapChain, 0); DX_RELEASE(m_swapChain, 0);
DX_RELEASE(m_deviceCtx, 0); DX_RELEASE(m_deviceCtx, 0);
@ -1611,7 +1611,7 @@ namespace bgfx { namespace d3d11
} }
DX_RELEASE(m_annotation, 1); DX_RELEASE(m_annotation, 1);
DX_RELEASE_WARNONLY(m_infoQueue, 0); DX_RELEASE_W(m_infoQueue, 0);
DX_RELEASE(m_msaaRt, 0); DX_RELEASE(m_msaaRt, 0);
DX_RELEASE(m_swapChain, 0); DX_RELEASE(m_swapChain, 0);
DX_RELEASE(m_deviceCtx, 0); DX_RELEASE(m_deviceCtx, 0);

View File

@ -1381,7 +1381,7 @@ namespace bgfx { namespace d3d12
} }
#if BX_PLATFORM_WINDOWS #if BX_PLATFORM_WINDOWS
DX_RELEASE_WARNONLY(m_infoQueue, 0); DX_RELEASE_W(m_infoQueue, 0);
#endif // BX_PLATFORM_WINDOWS #endif // BX_PLATFORM_WINDOWS
DX_RELEASE(m_rtvDescriptorHeap, 0); DX_RELEASE(m_rtvDescriptorHeap, 0);

View File

@ -62,10 +62,11 @@ namespace bgfx { namespace noop
} }
// Pretend we have no limits // Pretend we have no limits
g_caps.limits.maxTextureSize = 16384; g_caps.limits.maxTextureSize = 16384;
g_caps.limits.maxTextureLayers = 2048; g_caps.limits.maxTextureLayers = 2048;
g_caps.limits.maxFBAttachments = BGFX_CONFIG_MAX_FRAME_BUFFER_ATTACHMENTS; g_caps.limits.maxComputeBindings = g_caps.limits.maxTextureSamplers;
g_caps.limits.maxVertexStreams = BGFX_CONFIG_MAX_VERTEX_STREAMS; g_caps.limits.maxFBAttachments = BGFX_CONFIG_MAX_FRAME_BUFFER_ATTACHMENTS;
g_caps.limits.maxVertexStreams = BGFX_CONFIG_MAX_VERTEX_STREAMS;
} }
~RendererContextNOOP() ~RendererContextNOOP()