SketchUcation Premium Membership

 

 

Plugin beachballs seemingly randomly on first load

Plugin beachballs seemingly randomly on first load

Postby stuarth » Fri Mar 09, 2012 11:02 pm

Hi
I'm seeing a strange issue with a plugin I built in OS X. The first time it's run after loading SketchUp it will occasionally beachball. Not every time, and there's no special action taken on the first run that would explain its behavior. If it runs successfully the first time, it will run without problem again in the same session. Has anyone seen a similar problem? Where would you start to debug it?
stuarth
 
Posts: 4
Joined: Fri Dec 09, 2011 6:20 pm
Name: Stuart Hinson

Re: Plugin beachballs seemingly randomly on first load

Postby Dan Rathbun » Fri Mar 23, 2012 4:04 am

How about more info ??

What kind of a plugin is it ??

Did you properly module wrap it in a unique namespace ??

Does it use any Observers?
If so.. any of those with problems as ThomThom has graphed here?

Do you have the console open when you load it?
Are any exception messages output ??

Does it use a WebDialog ?
If so does it open one immediately upon loading ?

Does it use any platform specific interfaces, like AppleScript, etc ?
User avatar
Dan Rathbun
Top SketchUcator
 
Posts: 4069
Joined: Tue Oct 06, 2009 3:06 am
Location: Florida, USA
Name: Dan Rathbun
Operating system: Windows
SketchUp version: 8
License type: Pro
SketchUp use: education
Level of SketchUp: Advanced

Re: Plugin beachballs seemingly randomly on first load

Postby stuarth » Wed Mar 28, 2012 8:45 pm

Hi Dan. Thanks for the reply.

The plugin's fairly straight forward. Essentially it's traversing the model and counting components and material usage.

Good catch on the namespace issue. I'd overlooked that. I'll add it immediately.

No observers or platform specific interfaces.

It does open a WebDialog on load. I didn't realize that could be an issue. Very curious to hear more. Is there anything I can read about it?

Dan Rathbun wrote:How about more info ??

What kind of a plugin is it ??

Did you properly module wrap it in a unique namespace ??

Does it use any Observers?
If so.. any of those with problems as ThomThom has graphed here?

Do you have the console open when you load it?
Are any exception messages output ??

Does it use a WebDialog ?
If so does it open one immediately upon loading ?

Does it use any platform specific interfaces, like AppleScript, etc ?
stuarth
 
Posts: 4
Joined: Fri Dec 09, 2011 6:20 pm
Name: Stuart Hinson

Re: Plugin beachballs seemingly randomly on first load

Postby Dan Rathbun » Wed Mar 28, 2012 9:45 pm

stuarth wrote:The plugin's fairly straight forward. Essentially it's traversing the model and counting components and material usage.


You should not really need to "traverse" the model entities.

Code: Select all
numc = 0
numi = 0
matls = 0

model.definitions.each {|cdef|
  if cdef.instances.size > 0
    numc += 1
    numi += cdef.instances.size
    cdef.instances.each {|i| matls += 1 unless i.material.nil? }
  end
}


Each component definition keeps a list of all it's instances, no matter what their nesting level.

ADD: By iterating the Sketchup::DefinitionList collection object, for the model,... you skip having to ignore entity types, that you do not need to test, ie Edges, etc. And your iteration should be much faster. (I suspect the random beach-balling occurs with larger models, or those that may return entity types during the iteration that you did not expect, and your code may not handle well. ie Images, EdgeLoop, etc.)
Also.. as each Sketchup::ComponentInstance object shares it's definition's entities with all it's sibling instances (ie, the instance does not have unique drawing elements of it's own,) ... each used component's entities collection need only be iterated ONCE, to see if there are any "hardset" materials assigned to faces, etc. (Those with default material == nil will get the material assigned to the instance itself.)
So access to a definition entities collection, is quickest via the model's Sketchup::DefinitionList.

ADD #2: Do not use obj.typename == "Typestring" as it is very slow.. instead, use obj.is_a?(Sketchup::ClassName)
Last edited by Dan Rathbun on Wed Mar 28, 2012 11:38 pm, edited 2 times in total.
User avatar
Dan Rathbun
Top SketchUcator
 
Posts: 4069
Joined: Tue Oct 06, 2009 3:06 am
Location: Florida, USA
Name: Dan Rathbun
Operating system: Windows
SketchUp version: 8
License type: Pro
SketchUp use: education
Level of SketchUp: Advanced

Re: Plugin beachballs seemingly randomly on first load

Postby Dan Rathbun » Wed Mar 28, 2012 10:43 pm

stuarth wrote:It does open a WebDialog on load. I didn't realize that could be an issue. Very curious to hear more. Is there anything I can read about it?

Check the [ Code Snippets ] Index thread.

Which has Topical Sub indexes...

[Info] Platform Issues / Differences / Specifics
.. and see it's WebDialog section(s), under each platform (or concentrate on the Mac issues.)
User avatar
Dan Rathbun
Top SketchUcator
 
Posts: 4069
Joined: Tue Oct 06, 2009 3:06 am
Location: Florida, USA
Name: Dan Rathbun
Operating system: Windows
SketchUp version: 8
License type: Pro
SketchUp use: education
Level of SketchUp: Advanced

Re: Plugin beachballs seemingly randomly on first load

Postby Dan Rathbun » Thu May 31, 2012 5:05 am

Stuart.. have you updated to v8M3, and if so do you still see this slowness on loading ?
User avatar
Dan Rathbun
Top SketchUcator
 
Posts: 4069
Joined: Tue Oct 06, 2009 3:06 am
Location: Florida, USA
Name: Dan Rathbun
Operating system: Windows
SketchUp version: 8
License type: Pro
SketchUp use: education
Level of SketchUp: Advanced

Re: Plugin beachballs seemingly randomly on first load

Postby Michaelv » Sat Jun 02, 2012 6:50 pm

stuarth wrote:Hi
I'm seeing a strange issue with a plugin I built in OS X. The first time it's run after loading SketchUp it will occasionally beachball. Not every time, and there's no special action taken on the first run that would explain its behavior. If it runs successfully the first time, it will run without problem again in the same session. Has anyone seen a similar problem? Where would you start to debug it?



Mac "beachballs" differently regardless of your plugin.
I have a lot of plugins and the time to load is "variable". Sometimes it beachballs for a while, sometimes not.
It's almost like there is a cache somewhere, that is emptied after a while. It seems the first time I load SU in a while it takes more time, then it goes faster. Not as clear cut but kind of.

So the correlation may not be with YOUR plugin.

That said however, careful for loose ends as that will greatly lengthened the beachballing in general (make the short one long and the long one longer)
Michaelv
 
Posts: 95
Joined: Wed Mar 03, 2010 11:02 pm
Name: Michael

SketchUcation One-Liner Adverts

by Ad Machine » 5 minutes ago

Artisan Organic Toolset - a set of powerful organic modeling tools.

Premium Members get 20% discount!

Ad Machine
Robot
 
Posts: 2012


Return to Developers' Forum

Who is online

Users browsing this forum: DanielBowring, nana9118 and 5 guests