Hi devs! I came to a strange problem, where I can’t unregister an GeometryChangedEvent, and it’s causing an “Layout update is struggling to process current layout” error cause of recursive call.
Here I register callback, note that _tooltip
is a static field.
private static void ShowTooltip(KeyValuePair<VisualElement, TooltipInfo> kvp)
{
_tooltip.RegisterCallback<GeometryChangedEvent>((evt) => TooltipGeometryChanged(evt, kvp));
_tooltip.text = kvp.Key.tooltip;
}
And right after GeometryChangedEvent is rising:
private static void TooltipGeometryChanged(GeometryChangedEvent evt, KeyValuePair<VisualElement, TooltipInfo> kvp)
{
var target = evt.currentTarget as VisualElement;
target.UnregisterCallback<GeometryChangedEvent>((evt) => TooltipGeometryChanged(evt,kvp));
var elementSize = new Vector2(kvp.Key.resolvedStyle.width, kvp.Key.resolvedStyle.height);
var elementPos = new Vector2(kvp.Key.worldBound.x, kvp.Key.worldBound.y);
CalcTooltipPos(elementSize, elementPos, kvp.Value);
}
But despite this line, callback keeps rising in infinite loop =\
target.UnregisterCallback<GeometryChangedEvent>((evt) => TooltipGeometryChanged(evt,kvp));
What am I doing wrong?
Thanks in advance!