Skip to content

Commit

Permalink
fix a crash bug that occurred when the explorer.exe process was termi…
Browse files Browse the repository at this point in the history
…nated.
  • Loading branch information
hecomi committed Jun 20, 2021
1 parent 6bb70d6 commit 5e5b334
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 6 deletions.
Binary file modified Assets/uWindowCapture/Plugins/x86/uWindowCapture.dll
Binary file not shown.
Binary file modified Assets/uWindowCapture/Plugins/x86_64/uWindowCapture.dll
Binary file not shown.
21 changes: 15 additions & 6 deletions Plugins/uWindowCapture/uWindowCapture/WindowsGraphicsCapture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ namespace
{


bool CallWinRtApiWithExceptionCheck(const std::function<void()> &func, const std::string& name)
bool CallWinRtApiWithExceptionCheck(const std::function<void()> &func, const std::string& name) noexcept
{
try
{
Expand All @@ -40,14 +40,15 @@ bool CallWinRtApiWithExceptionCheck(const std::function<void()> &func, const std
catch (const winrt::hresult_error& e)
{
const int code = e.code();
char buf[32];
sprintf_s(buf, "0x%x", code);
Debug::Error(name, " threw an exception: ", buf);
char buf[256];
sprintf_s(buf, 256, "0x%x", code);
const auto msg = winrt::to_string(e.message());
Debug::Error(name, " threw an WinRT exception: ", buf, " ", msg);
return false;
}
catch (const std::exception& e)
{
Debug::Error(name, " threw an exception: ", e.what());
Debug::Error(name, " threw an std exception: ", e.what());
return false;
}
catch (...)
Expand Down Expand Up @@ -394,7 +395,15 @@ const wchar_t * WindowsGraphicsCapture::GetDisplayName() const

static const wchar_t invalid[] = L"";
if (!item_) return invalid;
if (item_.DisplayName().empty()) return invalid;

if (!CallWinRtApiWithExceptionCheck([&]
{
const auto displayName = item_.DisplayName();
}, "WindowsGraphicsCapture::GetDisplayName()"))
{
return invalid;
}

return item_.DisplayName().c_str();
}

Expand Down

0 comments on commit 5e5b334

Please sign in to comment.