In iPadOS, I'm building a tree on the screen using CALayer subclasses. Touching a visible node on the screen selects the node using CALayer.hitTest(CGPoint). This works reliably when I arrange the layers like this:
But when I rearrange the same CALayer objects to look like this, after an unpredictable number of touches on the a*b composite structure, the app dies with EXC_BAD_ACCESS:
Here is my code at the point of death. The LOOK HERE print statement just before invoking hitTest verifies that both layer and ksCGPoint have reasonable values.
Here is the stack trace:
Here is where the code actually dies in computeZ, which is called by CALayer.hitTest, which is invoked by VNode.touchesBegan, where VNode is a subclass of UIView.
Does anyone know what's going on here, or how to fix it?