Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Preserve the IRestrictedErrorInfo after reading it. #154

Closed
wants to merge 4 commits into from
Closed
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions swiftwinrt/Resources/Support/Error.swift
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,15 @@ public var E_XAMLPARSEFAILED : WinSDK.HRESULT {
private func getErrorDescription(expecting hr: HRESULT) -> String? {
var errorInfo: UnsafeMutablePointer<IRestrictedErrorInfo>?
guard GetRestrictedErrorInfo(&errorInfo) == S_OK else { return nil }
tristanlabelle marked this conversation as resolved.
Show resolved Hide resolved
guard let errorInfo else { return nil }

// From the docs: https://learn.microsoft.com/en-us/windows/win32/api/roerrorapi/nf-roerrorapi-getrestrictederrorinfo
// > GetRestrictedErrorInfo transfers ownership of the error object to the caller and clears the error state for the thread.
// For crash reporting purposes, it's useful to preserve the error info state.
SetRestrictedErrorInfo(errorInfo)

defer {
_ = errorInfo?.pointee.lpVtbl.pointee.Release(errorInfo)
_ = errorInfo.pointee.lpVtbl.pointee.Release(errorInfo)
}

var errorDescription: BSTR?
Expand All @@ -117,7 +124,7 @@ private func getErrorDescription(expecting hr: HRESULT) -> String? {
SysFreeString(capabilitySid)
}
var resultLocal: HRESULT = S_OK
_ = errorInfo?.pointee.lpVtbl.pointee.GetErrorDetails(
_ = errorInfo.pointee.lpVtbl.pointee.GetErrorDetails(
errorInfo,
&errorDescription,
&resultLocal,
Expand Down
Loading