Bug causes SketchUp Bugsplat

I have a bug in my Building Creator that causes a crash. I’m having trouble finding the source of the crash.

@colin I’m hoping that you can tell from the crash report what is causing the problem.

Here are two of the crashes that I submitted. Crash #187261, and Crash #187255

The crash only happens when the user is trying to align an object using the move tool. I think the problem is related to my MoveToolObserver, but I can’t seem to find the problem.

Either way SketchUp shouldn’t crash :wink:

MoveToolObserver code
  class MoveToolObserver < Sketchup::ToolsObserver
    @moving_object = false
    def onActiveToolChanged(_tools, tool_name, _tool_id)
      if tool_name == "MoveTool" && BC.instance_variable_get('@settings')['preferences']['use_enhanced_move_tool']
        #check to see if we can use the new move tool
        supported_types = ['door', 'overhead door', 'barn door', 'slider', 'window', 'Enclosed', 'Porch', 'cupola', 'dormer']
        if Sketchup.active_model.selection.count == 1
          ent1 = Sketchup.active_model.selection[0]
          use_tool = ent1.is_a?(Sketchup::ComponentInstance) && supported_types.include?(ent1.get_attribute('bc', 'type'))
        else
          new_s = BC.s.to_a.reject! do |ent|
            ent.is_a?(Sketchup::ComponentInstance) && ent.definition.get_attribute('bc', 'type').to_s.start_with?('C')
          end
          if new_s == 1
            ent = new_s[0]
            use_tool = ent.is_a?(Sketchup::ComponentInstance) && supported_types.include?(ent.get_attribute('bc', 'type'))
          end
        end
        Sketchup.active_model.select_tool(MoveTool.new) if use_tool

        @porches = []
        s = Sketchup.active_model.selection
        s1 = []
        s.each do |e|
          next unless e.is_a? Sketchup::ComponentInstance

          @porches.push(e.glued_to) if e.glued_to.is_a? Sketchup::ComponentInstance
          Sketchup.active_model.definitions.each do |cd|
            next unless cd.get_attribute('bc', 'type') == "C" + e.definition.name

            cd.instances.each do |i|
              s1.push i if (i.parent == e.parent) && (i.definition.name[0..4] != 'Porch')
            end
          end
        end
        s.add(s1)
      else
        @porches = []
        @moving_object = false
      end
    end

    def onToolStateChanged(_tools, tool_name, _tool_id, tool_state)
      return unless tool_name == "MoveTool"

      @moving_object = true if tool_state == 1
      if @moving_object && tool_state == 0
        BC.frame_job
        @moving_object = false
      end

      return unless @porches

      if (tool_state == 0) && (@porches.count > 0)
        Sketchup.active_model.start_operation('Move Openings', true, false, true)
        @porches.each do |p|
          BC.shed_cut_openings p
        end
        @porches = []
        Sketchup.active_model.commit_operation
        #BC.s.clear
        if tool_name == "MoveTool"
          Sketchup.send_action 'selectSelectionTool:'
          Sketchup.send_action 'selectMoveTool:'
        else
          Sketchup.send_action 'selectSelectionTool:'
        end
      end
    end
  end

Does it crash in SU2020 ?

Recalling that the last release added a new “stamp” mode to the MoveTool.

I reproduced it in 2018 and 2021. Didn’t try it in 2020.

Here is the video from the user (trimmed down from 26mb). Don’t laugh. I told him maybe SketchUp got tired.

I see a few problems.

(a) It is much better and faster to compare tool_id (Integer comparison vs String compare.)
Also the native tool names were bugged on older Mac versions.

(b) if new_s == 1
How can an enumerable (like an Array) ever be equal to an Integer ?

(c) Sketchup.active_model.select_tool(MoveTool.new) if use_tool
Changing the active tool in the midst of an active tool change callback where perhaps other extensions have yet to react to the current tool change is dangerous!

Also, there is more callback code following this method call to change the active tool.
Does it even ever get evaluated ?

(d) After the Observers overhaul for the SU2016 release, the ToolStateObserver is one of those observers that cache state changes and then “dump” them all at once after the tool completes a cycle.
Prior to the overhaul we got real time state change callback calls. Afterward, … not so much.
Some of the native tools (I think) got “overhauled” and some didn’t. Which kind is the native MoveTool ?

(e) I see the same dangerous thing in your onToolStateChanged callback. It’s making active tool changes in the midst of SketchUp going through a current callback queue for possibly multiple observers from possibly multiple extensions.
Could set up a vicious circle of callback calls.

First of all here is a brief overview of what the move tool does. I have a feature called ‘Use Enhanced Move Tool’ when it is turned on selecting to move tool will automatically switch to my custom move tool which duplicates the native move tool and adds additional functionality, like dimensioning, stamping, and placing multiple instances.

I saw that myself, and it looks like a bug. But I doubt that it is related to the issue at hand.

Yes it does. Basically it checks for ‘attached’ objects. So if you move a shed it would move all the openings along with it.

It would really help if I could reliably reproduce this!! Sometimes it crashes on the 1st or 2nd try, and other times I can’t get it to crash. It’s hard to debug that way :frowning:

Which SU versions did you use when submitting? And Windows or mac? (The crashes are submitted to different databases, so it helps if I know which one to look at.)

They are for Windows, 2021.

1 Like

Windows SU 2021

Now I can’t even reproduce the crash anymore :confounded:

Your bugsplat reports your SketchUp version as 21.1.169 - that isn’t any of the released versions. You got an old beta. Latest Windows version is 21.1.332. Make sure you update to the latest version before diving deeper into this. (Always a good thing to do when experiencing issues with software.)

2 Likes