Fix a bug where Terminal may crash or hang at shutdown (#1651)

* Fix a bug where Terminal may crash at shutdown
This commit is contained in:
Oscar Calvo 2019-06-26 15:15:01 -07:00 committed by Michael Niksa
parent 5dd1f8d38a
commit 45ad2d71bf
6 changed files with 18 additions and 6 deletions

View file

@ -46,10 +46,8 @@ namespace winrt::TerminalApp::implementation
// cause you to chase down the rabbit hole of "why is App not
// registered?" when it definitely is.
// See GH#1339. This is a workaround for MSFT:22116519
// We need this to prevent an occasional crash on teardown
AddRef();
m_inner.as<::IUnknown>()->Release();
// Initialize will become protected or be deleted when GH#1339 (workaround for MSFT:22116519) are fixed.
Initialize();
}
// Method Description:

View file

@ -9,6 +9,8 @@ namespace TerminalApp
{
App();
void Initialize();
// For your own sanity, it's better to do setup outside the ctor.
// If you do any setup in the ctor that ends up throwing an exception,
// then it might look like TermApp just failed to activate, which will

View file

@ -35,6 +35,7 @@
#include <winrt/Windows.ui.xaml.media.h>
#include <winrt/Windows.ui.xaml.input.h>
#include <winrt/Windows.UI.Xaml.Hosting.h>
#include <winrt/Microsoft.Toolkit.Win32.UI.XamlHost.h>
#include <windows.ui.xaml.media.dxinterop.h>

View file

@ -41,7 +41,10 @@ AppHost::AppHost() noexcept :
AppHost::~AppHost()
{
// destruction order is important for proper teardown here
_window = nullptr;
_app.Close();
_app = nullptr;
}
// Method Description:
@ -57,7 +60,6 @@ AppHost::~AppHost()
// - <none>
void AppHost::Initialize()
{
_app.Initialize();
_window->Initialize();
const auto handle = _window->GetHandle();
_app.Create(reinterpret_cast<uint64_t>(handle));

View file

@ -90,6 +90,16 @@
<DeploymentContent>true</DeploymentContent>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</NativeReferenceFile>
<!--
The reason why this is needed for ARM64 is unknown,
If not added, the centenial package will fail to include the XamlHost dll.
-->
<NativeReferenceFile Include="$(OpenConsoleDir)$(Platform)\$(Configuration)\TerminalApp\Microsoft.Toolkit.Win32.UI.XamlHost.dll" Condition="'$(Platform)'=='ARM64'">
<DeploymentContent>true</DeploymentContent>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</NativeReferenceFile>
<!--
the packaging project wont recurse through our dependencies, you have to
make sure that if you add a cppwinrt dependency to any of these projects,

View file

@ -41,7 +41,6 @@ Abstract:
#include <winrt/Windows.system.h>
#include <winrt/Windows.Foundation.Collections.h>
#include <winrt/Windows.UI.Xaml.Hosting.h>
#include <winrt/Microsoft.Toolkit.Win32.UI.XamlHost.h>
#include <windows.ui.xaml.hosting.desktopwindowxamlsource.h>
// Additional headers for various xaml features. We need: