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: 

Hard crash: return focus to starting document from a command with a dialog

3 REPLIES 3
SOLVED
Reply
Message 1 of 4
p.seem
531 Views, 3 Replies

Hard crash: return focus to starting document from a command with a dialog

Good evening,

 

I have found I can generate a hard crash of Fusion 360 (see, e.g., CER_183996679) by returning focus to the initial document from within a command.   By initial document, I mean the document that was active when you executed the command.

 

This is true whether you lose focus by creating a new document or opening an existing one, and whether you return focus by closing the new document or by using the activate() method of the initial document.  The code snippet below causes the hard crash every time:

 

def returnFocusTest():
    app = adsk.core.Application.get()
    startingDoc = app.activeDocument
    otherDoc = app.documents.add(adsk.core.DocumentTypes.FusionDesignDocumentType)
    adsk.doEvents()
    startingDoc.activate()
    adsk.doEvents()

 

However, this is only true when the command generates a command dialog.  Running returnFocusTest() as a script works fine.  As does putting it the command execute handler of a dialog-free command.  However, as soon as you add any command input to the create event handler (even if they go unused) then the function above causes Fusion 360 to crash on the activate() line.

 

I have a vague recollection of this issue being discussed several years ago, but I can't find any reference to it in the forums.  Has anyone else come across this?  Does anyone know a way around it?  And secondarily, is Autodesk aware of it?

 

Thank you everyone for your help.

3 REPLIES 3
Message 2 of 4
goyals
in reply to: p.seem

Thanks for posting and providing the steps to reproduced it. I created UP-40635 ticket in our internal bug tracking system. I hope fix should be available in January release of Fusion.



Shyam Goyal
Sr. Software Dev. Manager
Message 3 of 4
goyals
in reply to: goyals

We looked at it and sharing our findings. Adding a new document fires up a command internally and it is not recommended when an existing command is completing we should not fire a new command because it might lead to some weird behaviours while cleaning up the objects of the existing command. I hope it answer your query but in case you have follow up question then feel free to reach out to us. Thank you.



Shyam Goyal
Sr. Software Dev. Manager
Message 4 of 4
p.seem
in reply to: p.seem

Given autodesk's non-answer answer above, it doesn't sound like they intend to do anything to fix this crash.  So if anyone else comes across this issue, it's worth knowing there is a way around it.

 

This had the smell of a threading problem, and sure enough if you push the work (everything after 'otherDoc = ...') onto it's own thread (as in their ThreadEventHandler example) that allows your initial command to close cleanly so the rest of the work continues to execute without any errors/crashes.

 

I don't imagine that was very clear, so here's what I mean, for posterity.  This version of returnFocusTest works:

 

stopFlag = None
myCustomEvent = 'returnFocusCustomEventId'
startingDoc = None
    
def returnFocusTest():
    global startingDoc
    startingDoc = app.activeDocument
    app.documents.add(adsk.core.DocumentTypes.FusionDesignDocumentType)
    adsk.doEvents()
    
    # Create a new thread for the other processing.        
    global stopFlag        
    stopFlag = threading.Event()
    myThread = MyThread(stopFlag)
    myThread.start()      

class ThreadEventHandler(adsk.core.CustomEventHandler):
    def __init__(self):
        super().__init__()
    def notify(self, args):
        startingDoc.activate()
        adsk.doEvents() 
                
class MyThread(threading.Thread):
    def __init__(self, event):
        threading.Thread.__init__(self)
        self.stopped = event

    def run(self):
       self.stopped.wait(10)
       app.fireCustomEvent(myCustomEvent) 

 

 

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