Ruby strange error

Hi all,

in my code, I have this function

  def get_point(edge)
  	edge.vertices.map{|vertex| vertex.position}
  end

It’s work 100% of the time , but I don’t know when its provide me this error

Error: #<NoMethodError: undefined method `position' for #<Sketchup::OptionsProvider:0x00007fc8a781d518>>
...../Adebeo_SimpleTool_extension/Adebeo_SimpleTool/models/component_skeleton.rb:63:in `block in get_point'

But how a vertices method could return a OptionsProvider ?

thanks for your answer ?

Memory corruption, likely. Exit SketchUp. Reboot Computer.

If you can get a repeatable error with a certain model, a certain code snippet in the latest SketchUp version, please log a bug report in the API issue tracker.


Aside: Your method as shown returns an Array of two points, not a single point.

For Ruby 2+ (SU 2014 and higher) you can use the shorthand notation …

  def get_points(edge)
  	edge.vertices.map(&:position)
  end

And you can always do (which is likely faster) …

  def get_points(edge)
  	[ edge.start.position, edge.end.position ]
  end

May be related to …

https://github.com/SketchUp/api-issue-tracker/issues/619

Denis, what SketchUp version are you seeing this on ?

Also, if you see this occurring after a certain Ruby exception or a certain SketchUp application error, knowing this will also be helpful.

In fact this error appear after a lot of operation in ruby ( and DC calculation). Thanks for you help, I will refactor code as you advice.

1 Like

I’d agree @DanRathbun, that seems very likely to be another case of the zombie object issue (that’s me on GitHub btw).

1 Like

Sketchup 21.0.392 on MAC and PC

Yea, this is a clear case of zombie references.

I would not bother to try to handle this in your extension. If you are running into this then you’re only catching the errors when one type if confused for another type. In which case it’s good that the extension fails, because the alternative is worse, getting a reference of a different entity of the same type - then you’d blindly operate on a random entity. If you do any error handling at all for this I’d recommend it’s merely to inform the user to restart SketchUp because all bets are off when zombies has entered the system. Worst case scenario is random modification of the model data.

We’re seeing the same kind of errors in VR Sketch. For reference, during the last two weeks, we got 5 automated reports with this error, all about an OptionsProvider object showing up randomly (why OptionsProvider??), all on OS X. I tried previously to handle the exception by retrying the faulty piece of code a few times, but it seems not to help—i.e. we seem to get the same bogus OptionsProvider from reading the same attribute repeatedly. In view of the discussion here, I’ve now changed the logic to ask the user to restart SketchUp. I’ve also added a note that if someone can reproduce the problem, we’d be very interested in the model. We’ll see!

…Looking through the error logs of the past three months, the versions of SketchUp we see are all OS X, and most of them are 2100000392, plus a few 2000000362 (that’s Sketchup.version_number)—there is a bias, though, in that VR Sketch on OS X doesn’t really work with SU2019 or older.

Just want to mention that this error is still occurring with Sketchup 2023.

@armin.rigo @maxpleaner

Please add comments to the official tracking issue … and note platform and SketchUp build version:

Also, if you can provide a snippet of reproducible code, this will help track down the internal error.

Also, please note what major extensions you have installed and loading, especially render extensions.

Sorry, no reproducer here. Let me write down my thought on the bug report.

1 Like

Adding to the discussion here because it’s the only forum post I’ve encountered that appears to mention this issue.
I’ve been battling a similar NoMethodError that occurs in about a third of the models I open, when running the following method. An OptionsProvider object is somehow mixed in among the edge vertices in the model. Attempting to read keys/values from that OptionsProvider crashes SketchUp.

Any given open model either will or won’t throw the error, consistently. Meaning, if I open a model and the method does not throw the error, then I can run the method as many times as I’d like, and the error is never thrown. Whereas if I open a model and the method does throw the error, then every subsequent time I run the method, it throws the error.

Closing and re-opening the model seems to effectively “re-roll the dice” — a model that was not raising the error might raise the error after being closed and re-opened, and vice versa. I’ve even saved a copy of a model after encountering the error, closed and re-opened it, and no longer encountered the error.

System/Environment Details:
Mac M1 Max Ventura 13.4.1, SketchUp 24.0.483, the only enabled extensions are native SketchUp extensions (Add Location, Dynamic Components, Sandbox Tools, SketchUp Diffusion).

Method that throws the error:

def self.get_model_height()
  model = Sketchup.active_model
  entities = model.entities
  edges = entities.grep(Sketchup::Edge)
  vertices = edges.map(&:vertices).flatten.uniq
  z_values = vertices.map(&:position).map(&:z)  # Error occurs here trying to access :position of OptionsProvider object
  max_z = z_values.max
  min_z = z_values.min
  return (max_z - min_z).inch
end # get_model_height

Ruby console output error message:

get_model_height
Error: #<NoMethodError: undefined method `position' for #<Sketchup::OptionsProvider:0x00000002dfc857d0>>
(eval):6:in `map'
(eval):6:in `get_model_height'
(eval):1:in `<main>'
SketchUp:in `eval'

I’ve added the above to the official tracking issue on GitHub. I appreciate any insight you folks can offer. Hopefully those steps can be reproduced on your end and be helpful in figuring out what’s going on under the hood. Happy to provide more info if that would help.

EDIT: Attached example model in which this error has (and has not) occured.
SKP-LAFX-SHRB-PRNL-018.skp (80.4 KB)

1 Like

It might help if the report with the code had a “buggered” model to go along with the code snippet.


In the meantime, you can detect the memory corruption with the method like …

vertices = edges.map(&:vertices).flatten.uniq
if vertices.any? { |vert| !vert.respond_to?(:position) }
  # memory ist kaput!
end

You might also filter like …

vertices.select! { |vert| vert.respond_to?(:position) }

… but as @tt_su said above, you run the risk of model corruption.

Thanks, Dan. I’ve just edited my initial reply and attached an example model. I’ll use your suggested check to handle the error when it occurs in the meantime.

1 Like