Community
Fusion API and Scripts
Got a new add-in to share? Need something specialized to be scripted? Ask questions or share what you’ve discovered with the community.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Calling API from thread (C++)

2 REPLIES 2
Reply
Message 1 of 3
ryan65CCN
641 Views, 2 Replies

Calling API from thread (C++)

Hey Everyone,

 

I'm trying to use the Fusion 360 API in a spawned thread. It works the majority of the time but, other times Fusion crashes without throwing an exception back to the user code so, I can't catch it. The offending function is ImportManager::importToTarget(...). isValid() returns true for all the objects used by this function and nothing is null, so I can't detect when Fusion will crash. I use this function in the same way for both the main thread and the spawned thread and it doesn't crash in the main thread so, it's not an implementation issue. Is there a work-around for this? Alternatively, I can run the Fusion code in the main thread if there is a way to interrupt the main thread from the spawned thread (async timer, throw custom events, etc).

 

Here's what visual studio says about the crashes:

Exception thrown at 0x00007FFD394E1F28 in Fusion360.exe: Microsoft C++ exception: acis_exception at memory location 0x000000834FFFA030.
Exception thrown at 0x00007FFD0059FCD0 (NuBase10.dll) in Fusion360.exe: 0xC0000005: Access violation reading location 0x00000000000000F0.

 

Thanks,

Ryan

Tags (3)
2 REPLIES 2
Message 2 of 3
marshaltu
in reply to: ryan65CCN

Hello,

 

I would like to recommend you run API in main/UI thread. As you saw, there would be some unexpected errors if you run them in worker thread. Unfortunately there is no workaround for you.

 

Could you please explain a little bit about what you are going to do? We would estimate if it is necessary to expose new API to support the kind of requirements in the future release?

 

Thanks,

Marshal

 

 



Marshal Tu
Fusion 360 Developer
Autodesk, Inc.

Message 3 of 3
ryan65CCN
in reply to: marshaltu

Hey Marshal,

 

What I was trying to do was launch a GUI thread (using Qt) that can use the Fusion 360 API. Initially, I was looking for a way to interrupt the main thread from my Qt thread so the main thread could run Fusion code. The API doesn't have any way to set up a custom event so that's why I was trying to use the API in another thread. I found a workaround though, I set up an up key interrupt in the main thread that runs my code. Then from Qt, I change the focus to the main Fusion 360 window and simulate an up key. I can send messages between windows by using a shared object. It's not ideal since it makes the Qt window disappear (to the background) for like a tenth of a second when it changes focus and I need to keep a command window open so it can receive the up key. And often times the command window closes, so I have to keep recreating it. As far as API changes go, custom interrupts would be nice. But probably a better addition would be timer interrupts so you can run code in the main thread at a given interval (in my case I would poll for messages from the Qt thread every 100ms ).

 

For now, I am content with this work-around. Thanks for replying,

Ryan

Tags (4)

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report