• Login
sketchucation logo sketchucation
  • Login
⚠️ Libfredo 15.4b | Minor release with bugfixes and improvements Update

[Solved] My script keeps bugsplatting :(

Scheduled Pinned Locked Moved Developers' Forum
19 Posts 5 Posters 1.9k Views 5 Watching
Loading More Posts
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    thomthom
    last edited by thomthom 8 Jan 2009, 18:07

    I was testing my plugin, Selection Toys http://www.sketchucation.com/forums/scf/viewtopic.php?f=180&t=14975, some more and I found that it keeps crashing when try to select entities in the model attached. The mesh was created with sandbox tools. It also crashes if I manually draw a grid of 25x25 squares.

    It somewhat seems that it crashes when the amount of connected faces hits a certain point. But I can't understand why. Can anyone shed some light? I can't even view the raport detail when SU bugsplats on me.


    Angle Select.skp

    Thomas Thomassen β€” SketchUp Monkey & Coding addict
    List of my plugins and link to the CookieWare fund

    1 Reply Last reply Reply Quote 0
    • T Offline
      thomthom
      last edited by 8 Jan 2009, 18:14

      Did some testing. I started with a 2x2 tile then increased the size one step at the time. It worked fine all up to 10x10, but bugsplatted on 11x11.

      Thomas Thomassen β€” SketchUp Monkey & Coding addict
      List of my plugins and link to the CookieWare fund

      1 Reply Last reply Reply Quote 0
      • A Offline
        azuby
        last edited by 8 Jan 2009, 22:04

        If you can't see the error messages, send them to a file.

        azuby

        *error initus :: Blocks | CurrentDate | d/Code | extensionmanager | FFlipper | HideEdges | MeasuredArea | ModelHistory | PluginsHelp | PronButton | SAWSO | SCP | SUΒ²CATT

        Bad English? PM me, correct me. :smile:**

        1 Reply Last reply Reply Quote 0
        • T Offline
          thomthom
          last edited by 8 Jan 2009, 22:13

          you mean error messages in the ruby console? I'm note sure there are any since Sketchup simple crashes...

          Thomas Thomassen β€” SketchUp Monkey & Coding addict
          List of my plugins and link to the CookieWare fund

          1 Reply Last reply Reply Quote 0
          • T Offline
            thomthom
            last edited by 8 Jan 2009, 22:14

            Just realised that I didn't specify which function caused the error. It's the Select Connected Planar Faces, Select Connected by Material and Select Connected by Layer.

            Thomas Thomassen β€” SketchUp Monkey & Coding addict
            List of my plugins and link to the CookieWare fund

            1 Reply Last reply Reply Quote 0
            • T Offline
              thomthom
              last edited by 9 Jan 2009, 13:28

              It's odd, I've commented out every action, leaving just the method calls and loops in. Still crashes.

              Thomas Thomassen β€” SketchUp Monkey & Coding addict
              List of my plugins and link to the CookieWare fund

              1 Reply Last reply Reply Quote 0
              • M Offline
                Matt666
                last edited by 9 Jan 2009, 13:42

                When I have some loops in my codes, I put this to exit the loop when I've a bug...

                bug = 0
                lst = []
                while lst.class == Array && bug < 500
                bug += 1
                end
                puts bug.to_s
                

                If you don't have bug variable, his code crashes Skecthup. πŸ˜‰
                Your bug perhaps comes from a bugged loop ?

                Frenglish at its best !
                My scripts

                1 Reply Last reply Reply Quote 0
                • T Offline
                  thomthom
                  last edited by 9 Jan 2009, 13:52

                  That's what I'm wondering. But I don't understand why or what causes it. The script works fine for smaller meshes. But when there's about 100-110 faces with entities it has to traverse it bugsplats.
                  (I did some test with similar code. Though I has to put in a sleep command in order to see the number before SU splatted.)

                  Thomas Thomassen β€” SketchUp Monkey & Coding addict
                  List of my plugins and link to the CookieWare fund

                  1 Reply Last reply Reply Quote 0
                  • T Offline
                    tomasz
                    last edited by 9 Jan 2009, 14:03

                    You have probably a memory leak. Check amount of memory SU uses.
                    I had a big headache with SU2KT. It was the way I was writing entities into a hash.
                    Google didn't even bother to help me.

                    Tomasz

                    Author of [Thea Render for SketchUp](http://www.thearender.com/sketchup)

                    1 Reply Last reply Reply Quote 0
                    • T Offline
                      thomthom
                      last edited by 9 Jan 2009, 14:13

                      But it only loops through entities and adds it to the selection if it doesn't already contain that entity. Doesn't build a hash at all, even though I had plans for that for a variation of the tool.

                      I wonder if it's because it's recursing method.

                      Extract of the methods (contained in a module originally)

                      
                      	### FACES ### -----------------------------------------------------------
                      	# --- Select Connected Planar Faces ---
                      	def self.select_connected_planar_faces
                      		sel = Sketchup.active_model.selection
                      		original_face = sel[0]
                      		original_vector = original_face.normal
                      		
                      		self.get_planar_faces(original_face.edges, original_vector)
                      	end
                      	
                      	def self.get_planar_faces(edges, vector)	
                      		sel = Sketchup.active_model.selection
                      		# Loop through all the edges...
                      		edges.each { | edge |
                      			# ...get the faces and add the planar faces we haven't selected yet
                      			edge.faces.each { | face |
                      				if face.normal == vector && !sel.contains?(face)
                      					sel.add( face )
                      					self.get_planar_faces(face.edges, vector)
                      				end
                      			}
                      		}
                      	end
                      
                      

                      Thomas Thomassen β€” SketchUp Monkey & Coding addict
                      List of my plugins and link to the CookieWare fund

                      1 Reply Last reply Reply Quote 0
                      • T Offline
                        thomthom
                        last edited by 9 Jan 2009, 14:21

                        Maybe it crashes because the code run across the same entity so many times.

                        Maybe if I build a list if all entities I've checked and make sure I don't check the ones I have I can avoid the crash. For whatever reason it might be...

                        Thomas Thomassen β€” SketchUp Monkey & Coding addict
                        List of my plugins and link to the CookieWare fund

                        1 Reply Last reply Reply Quote 0
                        • T Offline
                          thomthom
                          last edited by 9 Jan 2009, 17:56

                          It appear to be the recursive part of the script. I just tried the Loop from Edge method I wrote earlier on a strip of 1x200 squares and that crashed as well.

                          But I don't know how I can do this without recursive methods.

                          Does this sound like a SketchUp bug rather than a script bug? I've not experienced any scripting languages that crashes on recursive methods like this.

                          Thomas Thomassen β€” SketchUp Monkey & Coding addict
                          List of my plugins and link to the CookieWare fund

                          1 Reply Last reply Reply Quote 0
                          • scottliningerS Offline
                            scottlininger
                            last edited by 9 Jan 2009, 18:01

                            Hey Thomthom,

                            Is this happening for you in SU6 or 7 or both?

                            There were a whole class of what we called "iterator" bugs that we fixed in SU7. These had to do with looping across entities in models. This crash sounds like it's similar.

                            Cheers,

                            • Scott Lininger
                              SketchUp Software Engineer
                              Have you visited the Ruby API Docs?
                            1 Reply Last reply Reply Quote 0
                            • T Offline
                              thomthom
                              last edited by 9 Jan 2009, 18:18

                              Yes. I was working with SU7, but I just tried SU6 and it happend there as well.

                              I just did little recursing test:

                              
                              	def self.select_connected_planar_faces
                              		@debug = 0
                              		self.recursive
                              	end
                              	
                              	@debug = 0
                              	def self.recursive
                              		@debug += 1
                              		puts @debug
                              		self.recursive
                              	end
                              
                              

                              The script reaches 489 (last number I see in the console before SU splats.
                              Doesn't seem to be related to iterating entities as this code simply is an infinite recursive loop.

                              But it will be triggered easily when iterating over lots of geometry. 😞

                              So I suppose this is one for the bug reports? Any preferred channel? Any way to track bug reports?

                              Thomas Thomassen β€” SketchUp Monkey & Coding addict
                              List of my plugins and link to the CookieWare fund

                              1 Reply Last reply Reply Quote 0
                              • T Offline
                                thomthom
                                last edited by 9 Jan 2009, 18:31

                                Appears that deep recursing is a problem in many languages. http://stackoverflow.com/questions/233013/how-does-your-favorite-language-handle-deep-recursion

                                Thomas Thomassen β€” SketchUp Monkey & Coding addict
                                List of my plugins and link to the CookieWare fund

                                1 Reply Last reply Reply Quote 0
                                • T Offline
                                  thomthom
                                  last edited by 9 Jan 2009, 19:24

                                  I refactored the code to an iterative loop instead of recursing.

                                  
                                  	### FACES ### -----------------------------------------------------------
                                  	# --- Select Connected Planar Faces ---
                                  	def self.select_connected_planar_faces
                                  		sel = Sketchup.active_model.selection
                                  		face = sel[0]
                                  		vector = face.normal
                                  		
                                  		edges = face.edges
                                  		while faces = select_connected(edges)	
                                  			# We now have a list of connected faces...
                                  			edges.clear()
                                  			faces.each { |face|
                                  				# ...check each face if it's co-planar
                                  				if !sel.contains?(face) && face.normal == vector
                                  					sel.add( face )
                                  					edges += face.edges
                                  				end
                                  			}
                                  		end
                                  	end
                                  	
                                  	def self.select_connected(edges)
                                  		ents = []
                                  		edges.each { |edge|
                                  			ents += edge.faces
                                  		}
                                  		return (ents.length > 0) ? ents ; nil
                                  	end
                                  
                                  

                                  Success! Haven't run into any limits yet.

                                  Basically: recursing is bad!

                                  Thomas Thomassen β€” SketchUp Monkey & Coding addict
                                  List of my plugins and link to the CookieWare fund

                                  1 Reply Last reply Reply Quote 0
                                  • M Offline
                                    Matt666
                                    last edited by 21 Jan 2009, 12:24

                                    @unknownuser said:

                                    Basically: recursing is bad!

                                    ...
                                    ...

                                    .........................................
                                    I often use this method... 😞 😞

                                    Frenglish at its best !
                                    My scripts

                                    1 Reply Last reply Reply Quote 0
                                    • T Offline
                                      thomthom
                                      last edited by 21 Jan 2009, 12:43

                                      Well, as long as you know that the recursing won't goo too deep it's ok. But when iterating over geometry it easily loops hundred or thousands of time which is when you end up with a call stack error.

                                      When I was looking around for a solution of this I found some interesting reading that converting to iterative loops instead of recursing can be much more efficient.

                                      Thomas Thomassen β€” SketchUp Monkey & Coding addict
                                      List of my plugins and link to the CookieWare fund

                                      1 Reply Last reply Reply Quote 0
                                      • M Offline
                                        Matt666
                                        last edited by 21 Jan 2009, 12:56

                                        Yep. Iterative method can save time compared with the recursive method... But recursing is much more beautiful !!

                                        Frenglish at its best !
                                        My scripts

                                        1 Reply Last reply Reply Quote 0
                                        • 1 / 1
                                        • First post
                                          Last post
                                        Buy SketchPlus
                                        Buy SUbD
                                        Buy WrapR
                                        Buy eBook
                                        Buy Modelur
                                        Buy Vertex Tools
                                        Buy SketchCuisine
                                        Buy FormFonts

                                        Advertisement