Skip to content

Commit

Permalink
Fix streetscape events are not updated after cached
Browse files Browse the repository at this point in the history
  • Loading branch information
asus4 committed May 20, 2024
1 parent d31b98c commit 12c37d5
Showing 1 changed file with 11 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ public sealed class ARStreetscapeGeometryManagerWithReplay : ARStreetscapeGeomet
{
private bool _useReplay = false;
private XRStreetscapeGeometrySubsystem _subsystem;

private Action<ARStreetscapeGeometriesChangedEventArgs>[] _updateHandlers;
private MulticastDelegate _updateDelegates;

private readonly Dictionary<TrackableId, ARStreetscapeGeometryWithReplay> _geometries = new();

Expand Down Expand Up @@ -102,23 +101,20 @@ private ARStreetscapeGeometry Convert(StreetscapeGeometry geometry)

private void InvokeChangedEvent(ARStreetscapeGeometriesChangedEventArgs args)
{
// Using cache to speed up invoke time
if (_updateHandlers != null)
if (_updateDelegates == null)
{
foreach (var handler in _updateHandlers)
{
handler?.Invoke(args);
}
const BindingFlags bindingFlags = BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic;
var field = typeof(ARStreetscapeGeometryManager).GetField("StreetscapeGeometriesChanged", bindingFlags)
?? throw new InvalidOperationException("Not found ARStreetscapeGeometryManager.StreetscapeGeometriesChanged");
_updateDelegates = (MulticastDelegate)field.GetValue(this);
}

var field = typeof(ARStreetscapeGeometryManager)
.GetField("StreetscapeGeometriesChanged", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
var eventDelegate = (MulticastDelegate)field.GetValue(this);
if (eventDelegate != null)
// Using cache to speed up invoke time
var handlers = _updateDelegates.GetInvocationList()
.Cast<Action<ARStreetscapeGeometriesChangedEventArgs>>();
foreach (var handler in handlers)
{
_updateHandlers = eventDelegate.GetInvocationList()
.Select(x => x as Action<ARStreetscapeGeometriesChangedEventArgs>)
.ToArray();
handler?.Invoke(args);
}
}
}
Expand Down

0 comments on commit 12c37d5

Please sign in to comment.