0

I wanted to add an obstacle to the obstacle graph, and interestingly it gives me a runtime error. Is there something that I could be missing or doing that is causing an error?

Playground code

import GameplayKit

let graph = GKObstacleGraph()

let barrier = GKPolygonObstacle(points: [
    float2(x: 200, y: 200),
    float2(x: 500, y: 200)
])

graph.addObstacles([barrier]) // error: Playground execution aborted: error: Execution was interrupted, reason: EXC_BAD_ACCESS (code=1, address=0x20).
The process has been left at the point where it was interrupted, use "thread return -x" to return to the state before expression evaluation.
MarkoCrush
  • 67
  • 8
  • Did you abbreviate for the post, or does your polygon have only two points? That’s a pretty degenerate polygon. – rickster Apr 30 '18 at 00:14
  • @rickster Yeah, I made the "polygon" only two points just to shorten up the code and point out that even when the GKPolygonObstacle has been made successfully, adding it to the GKObstacleGraph will cause some unexplained error. – MarkoCrush May 05 '18 at 18:33

1 Answers1

0

I also encountered this error, the solution I found was to create an SKShapeNode with a path between the two points and then use SKNode.obstacles(fromNodeBounds:) to create the obstacle. Also simply creating GKObstacleGraph() without parameters doesn't seem to work... you have to use GKObstacleGraph(obstacles: [GKPolygonObstacle], bufferRadius: Float, nodeClass: AnyClass) even if you give it an empty array of Obstacles.