Load_from_url freezes the interface during download in Sketchup 2017 and 2016

Hi!
I’m trying to develop a plugin that download files from my custom server but i’m getting problems in Sketchup 2017 and 2016 using definitions.load_from_url

Here’s a sample code:

def self.downloadModel()
        url = 'http://myserver.com/a.skp'
        mod = Sketchup::active_model
        cdef = mod.definitions.load_from_url(url)
        return unless cdef
        Sketchup.active_model.place_component(cdef)
    end

And here is the behavior:
Sketchup 2018 - Software keeps responsible during download and freezes during import (OK)
Sketchup 2017 - Software is irresponsible during download and import (BAD)
Sketchup 2016 - Software is irresponsible during download and import (BAD)

Usually if you don’t try to do things in the software after the download ends it get back but is very common random crashes when you try to interact with the interface during the download/import of the file in 2016 and 2017.

So how can i get models from web in Sketchup 2016 and 2017 without freezes the interface during the download?

Hmm… strange. We didn’t do anything to the API of the method for SU2018…
Maybe there were some other changes in our core related to downloads that changed this. I would have to dig into the source history.

Are you able to reliably reproduce this? Have you submitted the BugSplats? (Did you enter any information we can use to look up these crashes?)

For SU2017+ you could use the Sketchup::Http::Request class to perform a non-blocking download: Class: Sketchup::Http::Request — SketchUp Ruby API Documentation

For SU2016 I’m not sure. Ruby threads isn’t working properly within SketchUp. Something about it being hosted into a desktop application and how Ruby’s treads are all managed by Ruby makes it misbehaves. So you cannot use a Ruby thread to perform a download with Net::Http in the background I’m afraid. (And you’d have SSL issues if you tried to connect to an HTTPS connection because of issues with OpenSSL in those versions.)

definition = model.definitions.load_from_url(url, load_handler)

How/where do you set up the load_handler Class ?

It’s optional.

…hmm… now I’m starting wonder if using that would make it async… (Been a while since I used that method…)

Are you able to reliably reproduce this?

Not really, it’s quite random but it occurs very frequently.

For SU2017+ you could use the Sketchup::Http::Request class to perform a non-blocking download

Thanks will check about it.

How/where do you set up the load_handler Class ?

I already tried with and without the loader_handler using the progress method to send updates to the plugin but the result is the same. it works in the 2018 and freezes in 2017 e 2016

If you guys any other ideas how can i produce non blocking downloads inside SU2017 and 2016 please let me know.

Can you make sure to submit the bugsplat. Then give me nudge, with what SU version and platform - along with some keyboard in the report I can use to look it up in the database.

I had a look at the source to to refresh my memory. The download is synchronous only I’m afraid. So you’d have to provide your own download mechanism. As I mentioned, for SU2017 you could use Sketchup::Http. But for SU2016 is more complicated. You could look into make a Ruby C Extension and use a C/C++ library to perform the download async. We got example project on GitHub: GitHub - SketchUp/ruby-c-extension-examples: Ruby C extension examples

Hmm… this sounds odd. The code that download is synchronous - the logic that load the downloaded SKP file into the model executes on the next line - there is no callback here internally. So I’m surprised and puzzled to hear that you find SketchUp to be responsive while it downloads. Can you interact with it? (The viewport, menus etc?)

You could look into make a Ruby C Extension and use a C/C++ library to perform the download async.

Thanks i will take a look on it

Can you interact with it? (The viewport, menus etc?)

Sure. in SU2018 i do. I’m disappointed to know that it’s a bug not a feature.
I’m using windows 10 if that means something.

You can file feature requests and bug reports in our GitHub reporter. This would be a good one.