Why does face.followme crash Sketchup?

I have a function to create a face then use face.followme to build a model. The function is called several times. The all entities of the active model are deleted in each time before the function is invoked. It works well in the first, and second times calling. But Sketchup crashes when calling the function in the third, or the fourth time.

entities = Sketchup.active_model.entities.clear!

face = Sketchup.active_model.entities.add_face(face_points)
if face
  start = edges[0].start.position
  p1 = Geom::Point3d.new(start.x, start.y, start.z)
  p2 = Geom::Point3d.new(start.x, start.y, start.z + height)
  edge1 = Sketchup.active_model.entities.add_line(p1, p2)
  wall_group = Sketchup.active_model.entities.add_group(face)
  face.followme([edge1])  # Sketchup will not crash if comment out this line.
  edge1.hidden = true if !edge1.deleted?

If commenting out “face.followme([edge1])”, Sketchup does not crash even calling the function many times. So I guess that the followme method makes Sketchup crashed. What wrong with my code?

You can clone a point object …

p1 = start.clone

You can also offset a point object …

p2 = start.clone.offset!([0,0,height])

BUT … it is not necessary here to clone start for p1, just use start.
Also you should use the entities reference since you made it …

face = entities.add_face(face_points)
if face
  start = edges[0].start.position
  edge1 = entities.add_line(start, start.clone.offset!([0,0,height])
  # ...

We cannot know because we do not know what is wrong with your model, and you do not tell us what the values of face_points or height is.

Please always include a test model and a proper code method when asking questions as well as the values input to the method. (Ie, Ruby uses “methods” not “functions”.)

1 Like

If you experience crashes, please report it with a reproducible example in the issue tracker: Issues · SketchUp/api-issue-tracker · GitHub

Also include SketchUp version and OS version.

1 Like