Skip to content

Commit

Permalink
Fix scenarios where the managed object which the event handler is reg…
Browse files Browse the repository at this point in the history
…istered on is gone. (#795)
  • Loading branch information
manodasanW authored Apr 8, 2021
1 parent 7d70258 commit 2c38175
Show file tree
Hide file tree
Showing 9 changed files with 9 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/WinRT.Runtime/Projections/ICommand.net5.cs
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ private static unsafe int Do_Abi_remove_CanExecuteChanged_1(IntPtr thisPtr, glob
try
{
var __this = global::WinRT.ComWrappersSupport.FindObject<global::System.Windows.Input.ICommand>(thisPtr);
if (_CanExecuteChanged_TokenTables.TryGetValue(__this, out var __table) && __table.RemoveEventHandler(token, out var __handler))
if (__this != null && _CanExecuteChanged_TokenTables.TryGetValue(__this, out var __table) && __table.RemoveEventHandler(token, out var __handler))
{
__this.CanExecuteChanged -= __handler;
}
Expand Down
2 changes: 1 addition & 1 deletion src/WinRT.Runtime/Projections/ICommand.netstandard2.0.cs
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ private static unsafe int Do_Abi_remove_CanExecuteChanged_1(IntPtr thisPtr, glob
try
{
var __this = global::WinRT.ComWrappersSupport.FindObject<global::System.Windows.Input.ICommand>(thisPtr);
if (_CanExecuteChanged_TokenTables.TryGetValue(__this, out var __table) && __table.RemoveEventHandler(token, out var __handler))
if (__this != null && _CanExecuteChanged_TokenTables.TryGetValue(__this, out var __table) && __table.RemoveEventHandler(token, out var __handler))
{
__this.CanExecuteChanged -= __handler;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ private static unsafe int Do_Abi_remove_CollectionChanged_1(IntPtr thisPtr, glob
try
{
var __this = global::WinRT.ComWrappersSupport.FindObject<global::System.Collections.Specialized.INotifyCollectionChanged>(thisPtr);
if (_CollectionChanged_TokenTables.TryGetValue(__this, out var __table) && __table.RemoveEventHandler(token, out var __handler))
if (__this != null && _CollectionChanged_TokenTables.TryGetValue(__this, out var __table) && __table.RemoveEventHandler(token, out var __handler))
{
__this.CollectionChanged -= __handler;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ private static unsafe int Do_Abi_remove_CollectionChanged_1(IntPtr thisPtr, glob
try
{
var __this = global::WinRT.ComWrappersSupport.FindObject<global::System.Collections.Specialized.INotifyCollectionChanged>(thisPtr);
if (_CollectionChanged_TokenTables.TryGetValue(__this, out var __table) && __table.RemoveEventHandler(token, out var __handler))
if (__this != null && _CollectionChanged_TokenTables.TryGetValue(__this, out var __table) && __table.RemoveEventHandler(token, out var __handler))
{
__this.CollectionChanged -= __handler;
}
Expand Down
2 changes: 1 addition & 1 deletion src/WinRT.Runtime/Projections/INotifyDataErrorInfo.net5.cs
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ private static unsafe int Do_Abi_remove_ErrorsChanged_2(IntPtr thisPtr, global::
try
{
var __this = global::WinRT.ComWrappersSupport.FindObject<global::System.ComponentModel.INotifyDataErrorInfo>(thisPtr);
if (_ErrorsChanged_TokenTables.TryGetValue(__this, out var __table) && __table.RemoveEventHandler(token, out var __handler))
if (__this != null && _ErrorsChanged_TokenTables.TryGetValue(__this, out var __table) && __table.RemoveEventHandler(token, out var __handler))
{
__this.ErrorsChanged -= __handler;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ private static unsafe int Do_Abi_remove_ErrorsChanged_2(IntPtr thisPtr, global::
try
{
var __this = global::WinRT.ComWrappersSupport.FindObject<global::System.ComponentModel.INotifyDataErrorInfo>(thisPtr);
if (_ErrorsChanged_TokenTables.TryGetValue(__this, out var __table) && __table.RemoveEventHandler(token, out var __handler))
if (__this != null && _ErrorsChanged_TokenTables.TryGetValue(__this, out var __table) && __table.RemoveEventHandler(token, out var __handler))
{
__this.ErrorsChanged -= __handler;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ private static unsafe int Do_Abi_remove_PropertyChanged_1(IntPtr thisPtr, global
try
{
var __this = global::WinRT.ComWrappersSupport.FindObject<global::System.ComponentModel.INotifyPropertyChanged>(thisPtr);
if (_PropertyChanged_TokenTables.TryGetValue(__this, out var __table) && __table.RemoveEventHandler(token, out var __handler))
if (__this != null && _PropertyChanged_TokenTables.TryGetValue(__this, out var __table) && __table.RemoveEventHandler(token, out var __handler))
{
__this.PropertyChanged -= __handler;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ private static unsafe int Do_Abi_remove_PropertyChanged_1(IntPtr thisPtr, global
try
{
var __this = global::WinRT.ComWrappersSupport.FindObject<global::System.ComponentModel.INotifyPropertyChanged>(thisPtr);
if (_PropertyChanged_TokenTables.TryGetValue(__this, out var __table) && __table.RemoveEventHandler(token, out var __handler))
if (__this != null && _PropertyChanged_TokenTables.TryGetValue(__this, out var __table) && __table.RemoveEventHandler(token, out var __handler))
{
__this.PropertyChanged -= __handler;
}
Expand Down
2 changes: 1 addition & 1 deletion src/cswinrt/code_writers.h
Original file line number Diff line number Diff line change
Expand Up @@ -4428,7 +4428,7 @@ private static unsafe int Do_Abi_%%
try
{
var __this = global::WinRT.ComWrappersSupport.FindObject<%>(thisPtr);
if(_%_TokenTables.TryGetValue(__this, out var __table) && __table.RemoveEventHandler(%, out var __handler))
if(__this != null && _%_TokenTables.TryGetValue(__this, out var __table) && __table.RemoveEventHandler(%, out var __handler))
{
__this.% -= __handler;
}
Expand Down

0 comments on commit 2c38175

Please sign in to comment.