SketchUp / api-issue-tracker

Public issue tracker for the SketchUp and LayOut's APIs
https://developer.sketchup.com/
39 stars 10 forks source link

Sketchup:active_model issue in Ruby Console [mac]... #298

Open driven opened 5 years ago

driven commented 5 years ago
  1. SketchUp/LayOut Version: v19.2
  2. OS Platform: OS X

Describe: Ruby Console is INTERMITTENTLY calling :active_model methods on non-active background model... sometimes BugSplating like this Crash Report #12411 ... Describe what the expected result is. for the call to work on the foreground active model or error if it's not the referenced active model [like it always has]

# I have three models open
# one has a 3D model that I export images from
# second one I import the images and update them if I change in first model
# third model is for testing concepts, copy/pasting from other two models
# this code will often write the image to the 'third' model when working in the 'second'...

def reload_image(one, two = one, delete = true)
  model = Sketchup.active_model
  ents  = model.entities
  sel   = model.selection
  view  = model.active_view
  imgs = []
  imgs = sel.grep(Sketchup::Image)
  return ('select image/s') if imgs.empty?
  sel.clear
  imgs.each do |img|
    file = img.path
    file.include?(one) ? (file.sub!(one, two))  : (file.sub!(two, one)) unless two == one
    return unless File.exists?(file)
    new_img = ents.add_image(file, img.origin, img.width, img.height)
    img.erase! if delete
    sel.add(new_img) # so I can group them after a batch mode loop
  end
  if imgs.length < 2
    grp = ents.add_group(sel.grep(Sketchup::Image))
    grp.name = two
    sel.add(grp)
  end
end

## one of these is called after selecting an image or more
## result grouped if plural
## updated image/s
#reload_image('orthographic')
## replacement image/s
#reload_image('orthographic', 'perspective')
## additional image/s
reload_image('orthographic', 'perspective', false)

image_test.zip

john

thomthom commented 5 years ago

What are the steps to reproduce this? Just this snippet doesn't seem to do much...

thomthom commented 5 years ago

Can you share some models to go along with this?

driven commented 5 years ago

it's part of a fairly complex workflow, that I don't really want to share...

on a mac if you: open two new models and drag one of the supplied images to each...

test the variations on the call in one of the open models...

switch to the other model, define 'model'

model = Sketchup.active_model
ents  = model.entities
defs  = model.definitions
sel   = model.selection
view  = model.active_view

as you may if running other snippets then re-run [arrow up, return] a previous cmd...

switch back and forth [like you do] and at some point the code seems to break...

if you check the other model it's full of all the 'failed' imports...

RC appears to be getting references muddled, which even with really crap snippets never happened before v19.2

you should always get 'select image/s' message as you have swapped context, but 'on occasion' the 'reload_images' happens in the background model...

my concern is, if it's happening in the RC wight it happen from an extension...

john

thomthom commented 5 years ago

Are you saying this is a regression with 19.2?

Can you capture how to repro in a video? I'm still a little bit unclear on that to do...

driven commented 5 years ago

not a regression as far as I know...

it is a new bug in 19.2 that I have never seen or heard of since I started using Ruby Console v5/6...

for the type of things I was doing I have always just pasted in snippets and redefining them on the fly if need...

sometimes, things get messed up, but never has it affected another open model...

the Ruby Console has always operated on the foremost model window...

something seems to have changed...

I've moved past that point in what I'm doing, but if I need to revisit , I'll see if I can make a better repo and gif...