# Ruby strange error

**URL:** <https://forums.sketchup.com/t/ruby-strange-error/159666>\
**Category:** Ruby API\
**Tags:** sketchup, ruby\
**Created:** [April 6, 2021, 2:15pm UTC](https://forums.sketchup.com/t/ruby-strange-error/159666 "2021-04-06T14:15:29Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![denis\_bolomier](https://sea2.discourse-cdn.com/sketchup/user_avatar/forums.sketchup.com/denis_bolomier/32/1580_2.png) [@denis\_bolomier](https://forums.sketchup.com/u/denis_bolomier)\
**Post date:** [April 6, 2021, 2:15pm UTC](https://forums.sketchup.com/t/ruby-strange-error/159666/1 "2021-04-06T14:15:29Z")

</div>

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 ?

---

<div class="post-metadata">

**Author:** ![DanRathbun](https://sea2.discourse-cdn.com/sketchup/user_avatar/forums.sketchup.com/danrathbun/32/500_2.png) [@DanRathbun](https://forums.sketchup.com/u/DanRathbun)\
**Post date:** [April 6, 2021, 2:26pm UTC](https://forums.sketchup.com/t/ruby-strange-error/159666/2 "2021-04-06T14:26:03Z")

</div>

> [@denis\_bolomier](#):
>
> But how a vertices method could return a OptionsProvider ?

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](https://github.com/SketchUp/api-issue-tracker/issues).

* * *

**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 …

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

```

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

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

```

---

<div class="post-metadata">

**Author:** ![DanRathbun](https://sea2.discourse-cdn.com/sketchup/user_avatar/forums.sketchup.com/danrathbun/32/500_2.png) [@DanRathbun](https://forums.sketchup.com/u/DanRathbun)\
**Post date:** [April 6, 2021, 2:33pm UTC](https://forums.sketchup.com/t/ruby-strange-error/159666/3 "2021-04-06T14:33:28Z")

</div>

May be related to …

[https://github.com/SketchUp/api-issue-tracker/issues/619](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.

---

<div class="post-metadata">

**Author:** ![denis\_bolomier](https://sea2.discourse-cdn.com/sketchup/user_avatar/forums.sketchup.com/denis_bolomier/32/1580_2.png) [@denis\_bolomier](https://forums.sketchup.com/u/denis_bolomier)\
**Post date:** [April 6, 2021, 2:57pm UTC](https://forums.sketchup.com/t/ruby-strange-error/159666/4 "2021-04-06T14:57:41Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![archidave](https://avatars.discourse-cdn.com/v4/letter/a/958977/32.png) [@archidave](https://forums.sketchup.com/u/archidave)\
**Post date:** [April 6, 2021, 3:04pm UTC](https://forums.sketchup.com/t/ruby-strange-error/159666/5 "2021-04-06T15:04:49Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![denis\_bolomier](https://sea2.discourse-cdn.com/sketchup/user_avatar/forums.sketchup.com/denis_bolomier/32/1580_2.png) [@denis\_bolomier](https://forums.sketchup.com/u/denis_bolomier)\
**Post date:** [April 6, 2021, 3:52pm UTC](https://forums.sketchup.com/t/ruby-strange-error/159666/6 "2021-04-06T15:52:12Z")

</div>

Sketchup 21.0.392 on MAC and PC

---

<div class="post-metadata">

**Author:** ![tt\_su](https://sea2.discourse-cdn.com/sketchup/user_avatar/forums.sketchup.com/tt_su/32/17_2.png) [@tt\_su](https://forums.sketchup.com/u/tt_su)\
**Post date:** [April 7, 2021, 10:21am UTC](https://forums.sketchup.com/t/ruby-strange-error/159666/7 "2021-04-07T10:21:10Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![armin.rigo](https://sea2.discourse-cdn.com/sketchup/user_avatar/forums.sketchup.com/armin.rigo/32/52126_2.png) [@armin.rigo](https://forums.sketchup.com/u/armin.rigo)\
**Post date:** [April 27, 2021, 8:19pm UTC](https://forums.sketchup.com/t/ruby-strange-error/159666/8 "2021-04-27T20:19:17Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![maxpleaner](https://sea2.discourse-cdn.com/sketchup/user_avatar/forums.sketchup.com/maxpleaner/32/136481_2.png) [@maxpleaner](https://forums.sketchup.com/u/maxpleaner)\
**Post date:** [February 15, 2024, 5:35pm UTC](https://forums.sketchup.com/t/ruby-strange-error/159666/9 "2024-02-15T17:35:10Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![DanRathbun](https://sea2.discourse-cdn.com/sketchup/user_avatar/forums.sketchup.com/danrathbun/32/500_2.png) [@DanRathbun](https://forums.sketchup.com/u/DanRathbun)\
**Post date:** [February 15, 2024, 9:25pm UTC](https://forums.sketchup.com/t/ruby-strange-error/159666/10 "2024-02-15T21:25:05Z")

</div>

@armin.rigo @maxpleaner

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

- [Memory allocation error - zombie objects · Issue #619 · SketchUp/api-issue-tracker · GitHub](https://github.com/SketchUp/api-issue-tracker/issues/619)

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

---

<div class="post-metadata">

**Author:** ![DanRathbun](https://sea2.discourse-cdn.com/sketchup/user_avatar/forums.sketchup.com/danrathbun/32/500_2.png) [@DanRathbun](https://forums.sketchup.com/u/DanRathbun)\
**Post date:** [February 15, 2024, 9:34pm UTC](https://forums.sketchup.com/t/ruby-strange-error/159666/11 "2024-02-15T21:34:14Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![armin.rigo](https://sea2.discourse-cdn.com/sketchup/user_avatar/forums.sketchup.com/armin.rigo/32/52126_2.png) [@armin.rigo](https://forums.sketchup.com/u/armin.rigo)\
**Post date:** [April 17, 2024, 5:52am UTC](https://forums.sketchup.com/t/ruby-strange-error/159666/12 "2024-04-17T05:52:43Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![alex\_lfx](https://avatars.discourse-cdn.com/v4/letter/a/5daacb/32.png) [@alex\_lfx](https://forums.sketchup.com/u/alex_lfx)\
**Post date:** [May 21, 2024, 6:43pm UTC](https://forums.sketchup.com/t/ruby-strange-error/159666/13 "2024-05-21T18:43:45Z")

</div>

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:

```auto
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:

```auto
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](https://forums.sketchup.com/uploads/short-url/cto3kEe3prPSIMV4sHmJ6ZS8SoV.skp) (80.4 KB)

---

<div class="post-metadata">

**Author:** ![DanRathbun](https://sea2.discourse-cdn.com/sketchup/user_avatar/forums.sketchup.com/danrathbun/32/500_2.png) [@DanRathbun](https://forums.sketchup.com/u/DanRathbun)\
**Post date:** [May 21, 2024, 7:24pm UTC](https://forums.sketchup.com/t/ruby-strange-error/159666/14 "2024-05-21T19:24:42Z")

</div>

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 …

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

```

You might also filter like …

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

```

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

---

<div class="post-metadata">

**Author:** ![alex\_lfx](https://avatars.discourse-cdn.com/v4/letter/a/5daacb/32.png) [@alex\_lfx](https://forums.sketchup.com/u/alex_lfx)\
**Post date:** [May 21, 2024, 7:47pm UTC](https://forums.sketchup.com/t/ruby-strange-error/159666/15 "2024-05-21T19:47:07Z")

</div>

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.
