Revit API Forum
Welcome to Autodesk’s Revit API Forums. Share your knowledge, ask questions, and explore popular Revit API topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Revit crashes when second document is created/opened and DockableDialog is used

15 REPLIES 15
Reply
Message 1 of 16
i.nikolovVXJQ6
1698 Views, 15 Replies

Revit crashes when second document is created/opened and DockableDialog is used

Dear community,

 

I use the Dockable Panel example in Github created by Jeremy Tammik (https://github.com/jeremytammik/DockableDialog). However, lately I figured out a error appearing. It is appearing when the plugin is installed, even without opening the Dockable dialog. The issue can be reproduced, when you install the plugin. The open a first empty document. Now everything is ok. But when you create a second empty document Revit crashes. The error that is appearing is the following:

 

An unrecoverable error has occurred. The program will now be
terminated. All of your data has been recently saved, so there is no
need to create recover files.

 

I experience this issue on Revit 2017 and 2018. I did not test on other versions.

 

Could you please share if you know any possible reasons and solution?

 

Thank you in advance!

15 REPLIES 15
Message 2 of 16

Dear Ivan,

 

Thank you for your report and congratulations on ending up here in the right place after your comment on The Building Coder and raising an issue on the DockableDialog GitHub repo.

 

 

As I already said, I was not previously aware of the issue you describe.

 

Can you please provide a minimal reproducible case and the exact steps to observe the behaviour you describe?

 

http://thebuildingcoder.typepad.com/blog/about-the-author.html#1b

 

If you can use the DockableDialog as a starting point, maybe we can fix the issue for that as well, while we are at it.

 

Thank you!

 

Best regards,

 

Jeremy



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

Message 3 of 16

Dear Jeremy,

 

To reproduce and observe the behavior please follow the following steps:

 

1. Download the source code of the DockableDialog example from the GitHub repository.

 

DockableDialog source code

 

2. Build and install the plugin (I copy the .dll and .addin files under the Addins folder of Revit - C:\Users\nikolov.inn\AppData\Roaming\Autodesk\Revit\Addins\2018)

 

3. Open Revit (I tested in 2017 and 2018) and create new empty document (model)

 

4. Create a second new empty document (model) without closing the first one.

 

When the 4th step is reached Revit crashes with the following error message:

 

An unrecoverable error has occurred. The program will now be
terminated. All of your data has been recently saved, so there is no
need to create recover files.

 

Thank you for the interest in the issue and the help!

 

Best regards,

Ivan

Message 4 of 16

Dear Ivan,

 

Thank you for your description.

 

I performed the steps you describe and am unable to reproduce the issue my end.

 

I am working in Revit 2018.2:

 

  • 18.2.0.51
  • 20170927_1515(x64)
  • 2018.2

 

What version are you on?

 

I followed your four steps exactly.

 

I also updated the DockablePanel sample on GitHub for Revit 2018:

 

https://github.com/jeremytammik/DockableDialog/releases/tag/2018.0.0.0

 

Here is RevitLookup displaying the two open models inn the Application documents collection:

 

two_new_models.png

 

 

 

 

Best regards,

 

Jeremy



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

Message 5 of 16

Dear Jeremy,

 

Sorry, this is my mistake. Apparently, Revit was crashing because of my code within the DockableBrowser example. If I test just the DockableBrower is working fine. I have to understand now what causes the crash. I will keep you informed here in the thread.

 

Sorry again for the misleading post. 

 

Regards, 

Ivam

Message 6 of 16

Dear Ivan,

 

Thank you for letting us know.

 

Best regards,

 

Jeremy



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

Message 7 of 16

I get the same error in Revit 2019. The only things i changed about the https://github.com/jeremytammik/DockableDialog repository are:

  • setting the framework version to 4.7.1. 
  • referencing my local RevitApi.dll and RevitApiUi.dll 
  • set debug settings to start revit.exe

To reproduce the rror:

  1. Start Revit
  2. Press RegisterDockableWindow
  3. Open a document
  4. Close a document
  5. Open another document 

Revit crashes with the following message

 

System.InvalidOperationException: 'BuildWindowCore failed to return the hosted child window handle.'

When I remove the WebBrowser component from the sample, it works just fine. 

 

When I add the WebBrowser after loading the component and remove it immediately after adding, Revit will crash when opening a new document. 

So my guess is the WebBrowser component is causing the trouble here. 

Does anyone has any insight on this issue?

 

 

 

 

Message 8 of 16
psmith
in reply to: JohnnyRetro

Hi @JohnnyRetro  - I'm noticing that I'm going through the same issue as you. Were you able to resolve this ?

Message 9 of 16
psmith
in reply to: psmith

Resolved this by replacing the WPF browser control with CEFSharp.

Message 10 of 16
JimJia
in reply to: JohnnyRetro

Dear Preston Smith,

 

I am sorry to say that I can reproduce the same issue(my revit version: 20180216_1515(x64) 19.0.0.405).


I submitted the issue list item REVIT-144979 [Dockable Pane causes crash when editing family - case 15146734] on your behalf for the issue you find, as this issue requires exploration and possibly a modification to our software. Please make a note of this number for future reference.


You are welcome to request an update on the status of this issue or to provide us with additional information at any time quoting this wish list item number.


This issue is important to me. What can I do to help?


This issue needs to be assessed by our engineering team, and prioritized against all of the other change requests that are outstanding. As a result any information that you can provide to influence this assessment will help. Please provide the following where possible:
• Impact on your application and/or your development.
• The number of users affected.
• The potential revenue impact to you.
• The potential revenue impact to Autodesk.
• Realistic timescale over which a fix would help you.
• In the case of a request for a new feature or a feature enhancement, please also provide detailed Use Cases for the workflows that this change would address.

 

This information is extremely important. Our engineering team have limited resources, and so must focus their efforts on the highest impact Change Requests. We do understand that this will cause you delays and affect your development planning, and we appreciate your cooperation and patience.

 

 


Jim Jia
Autodesk Forge Evangelist
https://forge.autodesk.com
Developer Technical Services
Autodesk Developer Network
Email: Jim.Jia@autodesk.com
Message 11 of 16
psmith
in reply to: JimJia

Hi @JimJia -  I was able to resolve this on my own by replacing the WPF Browser Control with CEF Sharp's browser.

 

Message 12 of 16
JimJia
in reply to: psmith

Dear Dear Preston Smith,

I communicated with engineering team and I'm forwarding the messages from engineering team:

"This is a known limitation if you will with embedding the WIndows Forms WebBrowser controls inside of our dockable panes. Technically it has to do with the inability to "reparent" if you will the browser control, so each invocation of the Dockable pane (i.e. each project activation) requires a new control be generated and not reused, unlike other WPF or Winforms Framework elements. I have attached to this report a modified version of the DockableDialog sample that shows how to properly embed the control in question inside of a revit dockable view as of the 2018 API/version."

 


Jim Jia
Autodesk Forge Evangelist
https://forge.autodesk.com
Developer Technical Services
Autodesk Developer Network
Email: Jim.Jia@autodesk.com
Message 13 of 16
Mark.Ackerley
in reply to: JimJia

Thanks to JimJia for the code,

 

Just for posterity, I am registering the dialogue at startup without the 2 step, register, then open file... So in the startup I have 

FormToFrameWork Form = new FormToFrameWork();

then I separately have the class...

public class FormToFrameWork : IDockablePaneProvider, IFrameworkElementCreator
        {
            NewForm m_MyDockableWindow = null;
            public void SetupDockablePane(Autodesk.Revit.UI.DockablePaneProviderData data)
            {
                data.FrameworkElementCreator = this as IFrameworkElementCreator;
                data.InitialState = new DockablePaneState();
                data.InitialState.MinimumWidth = 300;
                data.VisibleByDefault = false;
                data.InitialState.DockPosition = DockPosition.Tabbed;
                data.InitialState.TabBehind = DockablePanes.BuiltInDockablePanes.ProjectBrowser;
            }

            public FrameworkElement CreateFrameworkElement()
            {
                m_MyDockableWindow = new NewForm();
                return m_MyDockableWindow;
            }
        }

 hopefully that is useful for someone 🙂

 

Cheers,

 

Mark

Message 14 of 16
dnenovMXKU9
in reply to: Mark.Ackerley

I have also run into this issue. In our case, the issue manifests itself when:

  1. using WebView2, new Microsoft control that supports HTML5 (could not use CEFSharp or any other for our use case)
  2. when opening/navigating to a second document; when closing all active documents

The solution was to handle all those cases manually and make sure to dispose of the active webView control and recreated it anew when the need arose. I made use of a few Revit events that would point to the exact moment when a new document was being opened and when where a document was about to close. For posterity, here is the code for our use case.

 

private MyPage page = null;
        //set default URL state
        private Uri urlState = new Uri("https://microsoft.com");    
        private bool IsInitiated = false;
        private bool IsVisible = false;
        private Document document;

        public void SetupDockablePane(DockablePaneProviderData data)
        {
            data.FrameworkElementCreator = this as IFrameworkElementCreator;
            data.InitialState = new DockablePaneState();
            data.InitialState.MinimumWidth = 300;
            data.VisibleByDefault = false;
            data.EditorInteraction = new EditorInteraction(EditorInteractionType.KeepAlive);
            data.InitialState.DockPosition = DockPosition.Right;
            data.InitialState.TabBehind = DockablePanes.BuiltInDockablePanes.ProjectBrowser;
        }

        public FrameworkElement CreateFrameworkElement()
        {
            page = new MyPage();
            return page;
        }

        // Close the current webView when opening a new document 
        public void A_VActivating(object sender, ViewActivatingEventArgs e)
        {
            RegisterDocument(e.NewActiveView.Document);
            if (e.NewActiveView.Document == null || e.CurrentActiveView.Document.Title != e.NewActiveView.Document.Title)
            {
                Close();
            }
        }
        // Register to the DocumentClosing event of the current document
        private void RegisterDocument(Document document)
        {
            try
            {
                this.document.DocumentClosing -= new EventHandler<DocumentClosingEventArgs>(D_DClosing);
            }
            catch (Exception) { }
            this.document = document;
            this.document.DocumentClosing += new EventHandler<DocumentClosingEventArgs>(D_DClosing);
        }
        // Create a new webView and navigate to the current url
        public void A_VActivated(object sender, ViewActivatedEventArgs e)
        {
            if(e.PreviousActiveView.Document.Title != e.CurrentActiveView.Document.Title)
            {
                this.page.Navigate(urlState);
            }
        }
        // Save the current url and kill the webView
        public void Close()
        {
            this.urlState = this.page.webView.Source;
            this.page.webView.Dispose();
        }
        // If we are about to close down the very last document, kill the webView
        internal void D_DClosing(object sender, DocumentClosingEventArgs e)
        {
            if(e.Document.Application.Documents.Size == 1)
            {
                this.document.DocumentClosing -= new EventHandler<DocumentClosingEventArgs>(D_DClosing);
                this.document = null;
                this.IsInitiated = false;
                Close();
            }
        }
        // Navigate for the first time (delay until dockable pane is on screen)
        internal void A_DFVChanged(object sender, DockableFrameVisibilityChangedEventArgs e)
        {
            this.IsVisible = e.DockableFrameShown;
            if (IsVisible && page != null && !IsInitiated)
            {
                this.page.Navigate(urlState, 1000);
                this.IsInitiated = true;
            }
        }

 

 

 

Oh, one more thing that could be of some value - the example code provided by the Autodesk Dev team was helpful, but also a bit confusing - you don't have to use a command to register a dockable pane in the application. This is what I do and it works fine.

 

 

        private static void CreateDockablePane(UIControlledApplication a)
        {
            bpage = new BrowserPage();            
            var dpid = new DockablePaneId(new Guid("3E545790-5D3B-475D-9280-81F4F0640C66"));
            a.RegisterDockablePane(dpid, "Architype Learn", bpage as IDockablePaneProvider);
            a.ViewActivating += new EventHandler<ViewActivatingEventArgs>(bpage.A_VActivating);
            a.ViewActivated += new EventHandler<ViewActivatedEventArgs>(bpage.A_VActivated);
            a.DockableFrameVisibilityChanged += new EventHandler<DockableFrameVisibilityChangedEventArgs>(bpage.A_DFVChanged);
        }

        public Result OnStartup(UIControlledApplication a)
        {
            MyApplication = a;  //Initialize MyApplication that will be used by the class

            AddRibbonPanel(a);
            CreateDockablePane(a);

            return Result.Succeeded;
        }

 

 

It's a mouthful but might be useful for someone down the road. 

Message 15 of 16

Thanks @dnenovMXKU9 I hadn’t seen this reply until just now.

Message 16 of 16

Dear all,

I guess it is an old topic but I got a link directly from here within P.S. and I guess it would be the best place to ask.


There it says that Dynamo would still crash the webview2 in a dockable panel. here i would have two questions:

1. is this the same if running the webview in a non dockable panel

2. was this solved somehow?

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


Rail Community