Display error messages on console, if available.

This commit is contained in:
Bartosz Taudul 2019-08-08 19:18:05 +02:00
parent aada588129
commit 3a221dafde

View File

@ -245,7 +245,35 @@ static inline void CpuId( uint32_t* regs, uint32_t leaf )
static void InitFailure( const char* msg ) static void InitFailure( const char* msg )
{ {
#if defined _WIN32 || defined __CYGWIN__ #if defined _WIN32 || defined __CYGWIN__
bool hasConsole = false;
bool reopen = false;
const auto attached = AttachConsole( ATTACH_PARENT_PROCESS );
if( attached )
{
hasConsole = true;
reopen = true;
}
else
{
const auto err = GetLastError();
if( err == ERROR_ACCESS_DENIED )
{
hasConsole = true;
}
}
if( hasConsole )
{
fprintf( stderr, "Tracy Profiler initialization failure: %s\n", msg );
if( reopen )
{
freopen( "CONOUT$", "w", stderr );
fprintf( stderr, "Tracy Profiler initialization failure: %s\n", msg );
}
}
else
{
MessageBoxA( nullptr, msg, "Tracy Profiler initialization failure", MB_ICONSTOP ); MessageBoxA( nullptr, msg, "Tracy Profiler initialization failure", MB_ICONSTOP );
}
#else #else
fprintf( stderr, "Tracy Profiler initialization failure: %s\n", msg ); fprintf( stderr, "Tracy Profiler initialization failure: %s\n", msg );
#endif #endif