Silent Terminate - Small Face

Dear friends,

        s_grp = Sketchup.active_model.active_entities.add_group
        @pt = [0, 0, 0]
        x = 10
        pts = [[1.94894, 1.22513, 0], [0.87372, 0.14991, 0], [0.82338, 0.10577, 0], [0.76772, 0.06857, 0], [0.70768, 0.03896, 0], [0.64428, 0.01744, 0], [0.57862, 0.00438, 0], [0.5118, 0, 0], [0.445, 0.00438, 0], [0.434067, 0.00655667, 0], [0.3794, 0.01744, 0], [0.316, 0.03896, 0], [0.265917, 0.063635, 0], [0.2559, 0.06857, 0], [0.247957, 0.0738843, 0], [0.2003, 0.10577, 0], [0.1571, 0.143604, 0], [0.1499, 0.14991, 0], [0.1058, 0.20024, 0], [0.0686, 0.25591, 0], [0.039, 0.31595, 0], [0.0175, 0.37935, 0], [0.0044, 0.44501, 0], [0, 0.51181, 0], [0, x + 0.5118, 0], [0.0044, x + 0.5786, 0], [0.0175, x + 0.6443, 0], [0.039, x + 0.7077, 0], [0.0686, x + 0.7677, 0], [0.1058, x + 0.8234, 0], [0.1499, x + 0.8737, 0], [0.2003, x + 0.9178, 0], [0.2559, x + 0.955, 0], [0.316, x + 0.9847, 0], [0.3794, x + 1.0062, 0], [0.445, x + 1.0192, 0], [0.5118, x + 1.0236, 0], [x + 0.5118, x + 1.0236, 0], [x + 0.5786, x + 1.0192, 0], [x + 0.6442, x + 1.0062, 0], [x + 0.7076, x + 0.9847, 0], [x + 0.7677, x + 0.955, 0], [x + 0.8233, x + 0.9178, 0], [x + 0.8737, x + 0.8737, 0], [x + 0.9178, x + 0.8234, 0], [x + 0.955, x + 0.7677, 0], [x + 0.9846, x + 0.7077, 0], [x + 1.0061, x + 0.6443, 0], [x + 1.0192, x + 0.5786, 0], [x + 1.0236, x + 0.5118, 0], [x + 1.0236, 0.51181, 0], [x + 1.0192, 0.44501, 0], [x + 1.0061, 0.37935, 0], [x + 0.9846, 0.31595, 0], [x + 0.955, 0.25591, 0], [x + 0.9178, 0.20024, 0], [x + 0.8737, 0.14991, 0], [x + 0.8233, 0.10577, 0], [x + 0.7677, 0.06857, 0], [x + 0.7076, 0.03896, 0], [x + 0.6442, 0.01744, 0], [x + 0.5786, 0.00438, 0], [x + 0.5118, 0, 0], [0.5118, 0, 0], [0.445, 0.00438, 0], [0.434067, 0.00655667, 0], [0.3794, 0.01744, 0], [0.316, 0.03896, 0], [0.265917, 0.063635, 0], [0.2559, 0.06857, 0], [0.247957, 0.0738843, 0], [0.2003, 0.10577, 0], [0.1571, 0.143604, 0], [0.1499, 0.14991, 0], [0.1058, 0.20024, 0], [0.0686, 0.25591, 0], [0.039, 0.31595, 0], [0.0175, 0.37935, 0], [0.0044, 0.44501, 0], [0, 0.51181, 0], [0.00438, 0.57862, 0], [0.01744, 0.64428, 0], [0.03896, 0.70768, 0], [0.06857, 0.76772, 0], [0.10577, 0.82338, 0], [0.14991, 0.87372, 0], [1.22513, 1.94894, 0]]

        ll = 0
        dis = 0
        for i in 0...pts.size
          ll = ll + pts[i].distance(pts[i + 1]) if i != pts.size - 1
        end
        for i in 0...pts.size
          pts[i].z = @pt.z + (0.5 / 2.54) - dis / ll * (1 / 2.54)
          dis = dis + pts[i].distance(pts[i + 1]) if i != pts.size - 1
        end
         p ll
        cp = pts.first
        vector1 = pts[0].vector_to(pts[1])
        edge1 = s_grp.entities.add_circle cp, vector1, (0.5 / 2.54)
        edge1 = s_grp.entities.weld(edge1)
        path1 = s_grp.entities.add_curve pts
        face2 = s_grp.entities.add_face(edge1)
#        face2.followme path1

Codes works well but if we add last line SU terminated!!! Any idea about this problem?

At first just about “bad” naming. I know it is a test code, but still better to give a more “communicative” name. I would call as edge1 circle1.
Then since it is a circle, you do not need to make a curve with a #weld since a circle is a ArcCurve, it is already “soft”.

But mostly that’s not why I quoted this line. If you put smaller radius ( eg. (0.1 / 2.54) there will no bugsplat. (Beside that, it will be not a proper pipe…)
image
It seams that the path1 radius is too small to create folowwme surface by a given face. Actually it is a kind of “known” limitation of SU, but…

…the interesting part is coming: if you do not include the last line of code, then manually make a followme, that will go (Beside that, it will be not a proper pipe…)
image

Let’s see what the others will say…

2 Likes

There are several things about the code that bother me, though I don’t know why any of them would lead to a crash.

I don’t understand why you keep converting values such as 0.5/2.54. This suggests that 0.5 was in cm and you want it in inches. You could just type 0.5.cm and get the same result already represented as a Length and with no assumption about model units. That would be terser and clearer as to your intent.

As @dezmo already noted, I don’t know why you name the return from add_circle as edge1. That method actually returns an Array of Edges, not a single Edge. The Edges in the Array have the associated metadata that marks them as a circle. The variable name “edge1” is misleading. If you actually want an Edge, you could take the [0] element of the return from add_circle. But from the ensuing code, that doesn’t seem to be what you want…

I also don’t know what you meant to accomplish by invoking weld on edge1 (actually an Array of Edges). Perhaps to obtain a Curve corresponding to them? The Edges comprising a circle are already welded - a circle is a variety of Curve. So, weld just returns an Array containing a remake of this already-existing Curve. It doesn’t actually weld anything new because it doesn’t need to. Plus, if you just want the Curve, you could get it by invoking #curve on any of the Edges. Weld is just a more obscure way to get the same result.

Then you do

face2 = s_grp.entities.add_face(edge1)

As I noted, edge1 is actually Array(Sketchup::Curve) as returned by #weld. I’m surprised that add_face accepted this as an argument and created the desired curve, as add_face expects a bare Curve, not an Array of Curves. The API should have rejected this as the wrong argument type. But since it worked, let’s move on.

Regardless of tidying up the code so the variable names make sense and so it doesn’t rely on undocumented behavior, I think that @dezmo is correct that the followme runs into issues with small Edges when going around the tight curves in the path. You can see the missing triangles that result in his screenshot…

With the followme restored in the code, it crashes for me too. It appears that Ruby aborted SketchUp for some reason I can’t diagnose but perhaps the developers can. I submitted a BugSplat report with a link back to this topic. The page that is supposed to acknowledge the submission froze, so I can’t share the crash number here. Perhaps @colin can look it up and refer it to an appropriate person, as it seems to me the API version shouldn’t crash when the GUI doesn’t.

3 Likes

The bugsplat is under Mac, SketchUp 2021, and is #14067.

I will try to get someone to look at the report, but I’m curious what the steps are to make it go wrong? When I try the sample code I don’t see anything that looks like an error, and certainly no crash.

Did you uncomment the final line that does the followme? That’s where the crash occurs.

As an experiment, I made a component from the output of the code without the followme. I then applied the “Dave method” before doing the followme manually. It ran without the missing patches @dezmo observed. But on looking inside the result I found this:

The two turns of the followme object intersect with each other! I wonder if this may be the cause of the crash?

3 Likes

Some day I will learn to read all of the instructions!

I reduced the test a bit. This still crashes:

s_grp = Sketchup.active_model.active_entities.add_group
@pt = [0, 0, 0]
x = 10
pts = [[1.94894, 1.22513, 0], [0.87372, 0.14991, 0], [0.82338, 0.10577, 0], [0.76772, 0.06857, 0], [0.70768, 0.03896, 0], [0.64428, 0.01744, 0], [0.57862, 0.00438, 0], [0.5118, 0, 0], [0.445, 0.00438, 0], [0.434067, 0.00655667, 0], [0.3794, 0.01744, 0], [0.316, 0.03896, 0], [0.265917, 0.063635, 0], [0.2559, 0.06857, 0], [0.247957, 0.0738843, 0], [0.2003, 0.10577, 0], [0.1571, 0.143604, 0], [0.1499, 0.14991, 0]]

    ll = 0
    dis = 0
    for i in 0...pts.size
      ll = ll + pts[i].distance(pts[i + 1]) if i != pts.size - 1
    end
    for i in 0...pts.size
      pts[i].z = @pt.z + (0.5 / 2.54) - dis / ll * (1 / 2.54)
      dis = dis + pts[i].distance(pts[i + 1]) if i != pts.size - 1
    end
     p ll
    cp = pts.first
    vector1 = pts[0].vector_to(pts[1])
    edge1 = s_grp.entities.add_circle cp, vector1, (0.5 / 2.54)
    edge1 = s_grp.entities.weld(edge1)
    path1 = s_grp.entities.add_curve pts
    face2 = s_grp.entities.add_face(edge1)

face2.followme path1

but if you remove ‘,[0.1499, 0.14991, 0]’ from the end of the array, then it doesn’t crash. If I delete earlier entries and leave that one in, it doesn’t crash.

Can you see anything significant about that point?

2 Likes

Interesting! I’m not at my computer now. I’ll take a look later.

A general observation. The code has no exception trapping anywhere.
Not wrapped around the whole snippet, nor around the entity creation method calls.

1 Like

True, though when I looked at the crash report it appeared that Ruby invoked abort, which crashed the app. I think that shouldn’t happen if an exception was raised. Of course, the Ruby Console vanished as of the crash, so if an exception was raised I wouldn’t see it reported.

I tested the small geometry idea. I took the coordinates and made them be 100x bigger, and had no problems. Tried again at 10x bigger, and still no problems. At 2x bigger the crash came back.

Here’s the 10x bigger test:

s_grp = Sketchup.active_model.active_entities.add_group
@pt = [0, 0, 0]
x = 10
pts = [19.489,12.251,0],[8.737,1.499,0],[8.233,1.057,0],[7.677,0.685,0],[7.076,0.389,0],[6.442,0.174,0],[5.786,0.043,0],[5.118,0,0],[4.45,0.043,0],[4.34,0.065,0],[3.794,0.174,0],[3.16,0.389,0],[2.659,0.636,0],[2.559,0.685,0],[2.479,0.738,0],[2.003,1.057,0],[1.571,1.436,0],[1.499,1.499,0],[1.058,2.002,0],[0.686,2.559,0],[0.39,3.159,0],[0.175,3.793,0],[0.044,4.45,0],[0,5.118,0],[0,5.118,0],[0.044,5.786,0],[0.175,6.443,0],[0.39,7.077,0],[0.686,7.677,0],[1.058,8.234,0],[1.499,8.737,0],[2.003,9.178,0],[2.559,9.55,0],[3.16,9.847,0],[3.794,10.062,0],[4.45,10.192,0],[5.118,10.236,0],[5.118,10.236,0],[5.786,10.192,0],[6.442,10.062,0],[7.076,9.847,0],[7.677,9.55,0],[8.233,9.178,0],[8.737,8.737,0],[9.178,8.234,0],[9.55,7.677,0],[9.846,7.077,0],[10.061,6.443,0],[10.192,5.786,0],[10.236,5.118,0],[10.236,5.118,0],[10.192,4.45,0],[10.061,3.793,0],[9.846,3.159,0],[9.55,2.559,0],[9.178,2.002,0],[8.737,1.499,0],[8.233,1.057,0],[7.677,0.685,0],[7.076,0.389,0],[6.442,0.174,0],[5.786,0.043,0],[5.118,0,0],[5.118,0,0],[4.45,0.043,0],[4.34,0.065,0],[3.794,0.174,0],[3.16,0.389,0],[2.659,0.636,0],[2.559,0.685,0],[2.479,0.738,0],[2.003,1.057,0],[1.571,1.436,0],[1.499,1.499,0],[1.058,2.002,0],[0.686,2.559,0],[0.39,3.159,0],[0.175,3.793,0],[0.044,4.45,0],[0,5.118,0],[0.043,5.786,0],[0.174,6.442,0],[0.389,7.076,0],[0.685,7.677,0],[1.057,8.233,0],[1.499,8.737,0],[12.251,19.489,0]

ll = 0
dis = 0
for i in 0...pts.size
  ll = ll + pts[i].distance(pts[i + 1]) if i != pts.size - 1
end
for i in 0...pts.size
  pts[i].z = @pt.z + (0.5 / 2.54) - dis / ll * (1 / 2.54)
  dis = dis + pts[i].distance(pts[i + 1]) if i != pts.size - 1
end
 p ll
cp = pts.first
vector1 = pts[0].vector_to(pts[1])
edge1 = s_grp.entities.add_circle cp, vector1, (0.5 / 2.54)
edge1 = s_grp.entities.weld(edge1)
path1 = s_grp.entities.add_curve pts
face2 = s_grp.entities.add_face(edge1)

face2.followme path1

Don’t worry, I didn’t do the changes manually! A bit of JavaScript did that for me.

2 Likes

Thank you. I will follow your advice.

Also I try to understanding something from points but at end of day, I cannot understand why SU terminate. I believe it is a big problem in SU and also I tried to send report for it.

Also I think some unwanted small lines come to my points and caused this problem. I will recreate points and check again. I hope SU team find a solution for such problem.

        s_grp = Sketchup.active_model.active_entities.add_group
        @pt = [0, 0, 0]
        x = 10 
        pts = [[2.90573, 2.18192, 0], [2.07057, 1.34676, 0], [1.96457, 1.26542, 0], [1.84113, 1.21429, 0], [1.70866, 1.19685, 0], [1.57619, 1.21429, 0], [1.45276, 1.26542, 0], [1.34676, 1.34676, 0], [1.26542, 1.45276, 0], [1.21429, 1.57619, 0], [1.19685, 1.70866, 0], [1.19685, x + 2.0709, 0], [1.21429, x + 2.2033, 0], [1.26542, x + 2.3268, 0], [1.34676, x + 2.4328, 0], [1.45276, x + 2.5141, 0], [1.57619, x + 2.5652, 0], [1.70866, x + 2.5827, 0], [x + 2.0709, x + 2.5827, 0], [x + 2.2033, x + 2.5652, 0], [x + 2.3268, x + 2.5141, 0], [x + 2.4328, x + 2.4328, 0], [x + 2.5141, x + 2.3268, 0], [x + 2.5652, x + 2.2033, 0], [x + 2.5827, x + 2.0709, 0], [x + 2.5827, 1.70866, 0], [x + 2.5652, 1.57619, 0], [x + 2.5141, 1.45276, 0], [x + 2.4328, 1.34676, 0], [x + 2.3268, 1.26542, 0], [x + 2.2033, 1.21429, 0], [x + 2.0709, 1.19685, 0], [1.70866, 1.19685, 0], [1.57619, 1.21429, 0], [1.45276, 1.26542, 0], [1.34676, 1.34676, 0], [1.26542, 1.45276, 0], [1.21429, 1.57619, 0], [1.19685, 1.70866, 0], [1.21429, 1.84113, 0], [1.26542, 1.96457, 0], [1.34676, 2.07057, 0], [2.18192, 2.90573, 0]]
       
        ll = 0
        dis = 0
        for i in 0...pts.size - 1
          ll = ll + pts[i].distance(pts[i + 1])
        end
        for i in 0...pts.size - 1
          pts[i].z = @pt.z + (0.5.cm) - dis / ll * (1.cm)
          dis = dis + pts[i].distance(pts[i + 1])
        end
        cp = pts.first
        vector1 = pts[0].vector_to(pts[1])
        circle1 = s_grp.entities.add_circle cp, vector1, (0.5.cm)
        path1 = s_grp.entities.add_curve pts
        face2 = s_grp.entities.add_face(circle1)
        face2.followme path1

I used these points. Just I deleted unwanted small lines and SU works well. Also you can see result in following picture.

Yes. In the original code - in the path “radius” - there is a couple of small (~0.2mm) edges while the other ones are average ~1,7mm. In addition, they protrude from the normal “straightness”.
image

So, I think the solution is: keep in mind that SU “does not play nice” with small edges. Make sure the edge is larger than 1 mm. (or even more)



BTW. I guess the SU devs are aware of it, since they basically forbid some operations that cause little edges. (See e.g. Circle Tool)
image
(You should do the similar with your Tool) :wink:

1 Like

Receiving an error message that you have too small dimension is acceptable but terminate SU…

Was this ever logged or should there be an API issue opened in the GitHub tracker ? @tt_su

EDIT : I suppose this would be covered by Issue #15 - bugsplat using followme tool

hm… this might be related. I added a comment to the ticket.

Strange that the API followme crashes but using the Follow Me tool works fine (apart from lost faces that are too small)