sketchucation logo sketchucation
    • Login
    ℹ️ Licensed Extensions | FredoBatch, ElevationProfile, FredoSketch, LayOps, MatSim and Pic2Shape will require license from Sept 1st More Info

    [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.
    • thomthomT Offline
      thomthom
      last edited by

      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
      • thomthomT Offline
        thomthom
        last edited by

        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
        • thomthomT Offline
          thomthom
          last edited by

          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

            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
            • thomthomT Offline
              thomthom
              last edited by

              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
              • thomthomT Offline
                thomthom
                last edited by

                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
                • thomthomT Offline
                  thomthom
                  last edited by

                  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

                    @unknownuser said:

                    Basically: recursing is bad!

                    ...
                    ...

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

                    Frenglish at its best !
                    My scripts

                    1 Reply Last reply Reply Quote 0
                    • thomthomT Offline
                      thomthom
                      last edited by

                      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

                        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