Show GPU info (if available) in assert

This commit is contained in:
Jupeyy 2023-05-27 09:51:22 +02:00
parent 144bb1dd7f
commit 70d48140f0
6 changed files with 34 additions and 2 deletions

View file

@ -293,6 +293,7 @@ public:
MESSAGE_BOX_TYPE_INFO,
};
virtual void ShowMessageBox(const char *pTitle, const char *pMessage, EMessageBoxType Type = MESSAGE_BOX_TYPE_ERROR) = 0;
virtual void GetGPUInfoString(char (&aGPUInfo)[256]) = 0;
};
class IGameClient : public IInterface

View file

@ -4631,8 +4631,19 @@ int main(int argc, const char **argv)
char aVersionStr[128];
if(!os_version_str(aVersionStr, sizeof(aVersionStr)))
str_copy(aVersionStr, "unknown");
char aMessage[512];
str_format(aMessage, sizeof(aMessage), "An assertion error occured. Please write down or take a screenshot of the following information and report this error.\nPlease also share the assert log which you should find in the 'dumps' folder in your config directory.\n\n%s\n\nPlatform: %s\nGame version: %s %s\nOS version: %s", pMsg, CONF_PLATFORM_STRING, GAME_RELEASE_VERSION, GIT_SHORTREV_HASH != nullptr ? GIT_SHORTREV_HASH : "", aVersionStr);
char aGPUInfo[256];
pClient->GetGPUInfoString(aGPUInfo);
char aMessage[768];
str_format(aMessage, sizeof(aMessage),
"An assertion error occured. Please write down or take a screenshot of the following information and report this error.\n"
"Please also share the assert log which you should find in the 'dumps' folder in your config directory.\n\n"
"%s\n\n"
"Platform: %s\n"
"Game version: %s %s\n"
"OS version: %s\n\n"
"%s", // GPU info
pMsg, CONF_PLATFORM_STRING, GAME_RELEASE_VERSION, GIT_SHORTREV_HASH != nullptr ? GIT_SHORTREV_HASH : "", aVersionStr,
aGPUInfo);
pClient->ShowMessageBox("Assertion Error", aMessage);
// Client will crash due to assertion, don't call PerformAllCleanup in this inconsistent state
});
@ -5046,3 +5057,15 @@ void CClient::ShowMessageBox(const char *pTitle, const char *pMessage, EMessageB
if(m_pGraphics == nullptr || !m_pGraphics->ShowMessageBox(GetSdlMessageBoxFlags(Type), pTitle, pMessage))
SDL_ShowSimpleMessageBox(GetSdlMessageBoxFlags(Type), pTitle, pMessage, nullptr);
}
void CClient::GetGPUInfoString(char (&aGPUInfo)[256])
{
if(m_pGraphics != nullptr && m_pGraphics->IsBackendInitialized())
{
str_format(aGPUInfo, std::size(aGPUInfo), "GPU: %s - %s - %s", m_pGraphics->GetVendorString(), m_pGraphics->GetRendererString(), m_pGraphics->GetVersionString());
}
else
{
str_copy(aGPUInfo, "Graphics backend was not yet initialized.");
}
}

View file

@ -553,6 +553,7 @@ public:
#endif
void ShowMessageBox(const char *pTitle, const char *pMessage, EMessageBoxType Type = MESSAGE_BOX_TYPE_ERROR) override;
void GetGPUInfoString(char (&aGPUInfo)[256]) override;
};
#endif

View file

@ -3286,6 +3286,11 @@ bool CGraphics_Threaded::ShowMessageBox(unsigned Type, const char *pTitle, const
return m_pBackend->ShowMessageBox(Type, pTitle, pMsg);
}
bool CGraphics_Threaded::IsBackendInitialized()
{
return m_pBackend != nullptr;
}
const char *CGraphics_Threaded::GetVendorString()
{
return m_pBackend->GetVendorString();

View file

@ -1300,6 +1300,7 @@ public:
SWarning *GetCurWarning() override;
bool ShowMessageBox(unsigned Type, const char *pTitle, const char *pMsg) override;
bool IsBackendInitialized() override;
bool GetDriverVersion(EGraphicsDriverAgeType DriverAgeType, int &Major, int &Minor, int &Patch, const char *&pName, EBackendType BackendType) override { return m_pBackend->GetDriverVersion(DriverAgeType, Major, Minor, Patch, pName, BackendType); }
bool IsConfigModernAPI() override { return m_pBackend->IsConfigModernAPI(); }

View file

@ -523,6 +523,7 @@ public:
// returns true if the error msg was shown
virtual bool ShowMessageBox(unsigned Type, const char *pTitle, const char *pMsg) = 0;
virtual bool IsBackendInitialized() = 0;
protected:
inline CTextureHandle CreateTextureHandle(int Index)