Autodesk/revit-ifc

PR: After referencing IFC from RVT (.ifc converted to .ifc.rvt) Revit crashed upon exit

Opened this issue · 1 comments

Problem Description

I wrote simple plugin to automatically convert ifc file to rvt by using the code snippet below.
Convertion process by referencing ifc finishes successfully,
afterwards I issue command to shutdown Revit app, which results in a strange crash.

What I might be doing wrong?

Crash's description from journal as follows:

'C 12-Jul-2024 11:46:38.803; DBG_WARN: IFC: ODA: Can't unload locked modules
'Locked modules:
'IfcCore.dll:21
'IfcGeom.dll:1
'sdai.tx:6
'TD_DbRoot.dll:4
'
'
'Expect a soft crash after this warning.
'
'ApplicationException is being thrown on behalf of the function <void __cdecl ODAManager::uninitialize(void)>. Dump file: C:\Users\Rostislav\AppData\Local\Autodesk\Revit\Autodesk Revit 2024\Journals\journal.0002.0001.dmp: line 1426 of E:\Ship24.2\2024_px64\Source\Interface\IntfIFC\Source\IFCToolkitWrapper.cpp.
' 0:< Exception occurred
'C 12-Jul-2024 11:46:38.804; 0:< ExceptionCode=0xe06d7363 ExceptionFlags=0x00000081 ExceptionAddress=00007FFE84BEFABC
'C 12-Jul-2024 11:46:38.804; BC: 4,0,1
' 0:< System (MB) [Available / Total ] [Revit Memory Usage (MB) ]
' 0:< RAM Statistics: 18395 / 32433 1392=InUse 1640=Peak
' 0:< VM Statistics: 134177047 / 134217727 1155=InUse 1603=Peak
' 0:< ::9542:: Delta VM: Avail +26 -> 134177069 MB, Used 1155 MB; RAM: Avail +30 -> 18425 MB, Used 1392 MB
' 0:< GUI Resource Usage GDI: Avail 9792, Used 208, User: Used 103
' 0:< CefSharp has been shutdown successfully!
' 0:< Unconverted MessageBox "..."
' 0:< ::9542:: Delta VM: Avail +79 -> 134177149 MB, Used -10 -> 1145 MB; RAM: Avail -76 -> 18350 MB, Used -2 -> 1390 MB
' 0:< GUI Resource Usage GDI: Avail 9789, Used 211, User: Used 106
'H 12-Jul-2024 11:47:10.803; 0:<
Jrn.Data 'C 12-Jul-2024 11:47:10.804; DBG_WARN: idsdk_init fails #3005: line 147 of E:\Ship24.2\2024_px64\Source\Foundation\Utility\AdWebServiceIdSDKImpl.cpp.
_
"MessageBox" , "IDOK" , "...."
'C 12-Jul-2024 11:47:10.804; 0:< License shutdown starting
'C 12-Jul-2024 11:47:10.878; 0:< License cleanup complete: 20, 0
' 0:< CefSharp has been shutdown successfully!
'C 12-Jul-2024 11:47:10.878; program terminated

using System;
using System.IO;
using System.Runtime.InteropServices;
using Autodesk.Revit.ApplicationServices;
using Autodesk.Revit.Attributes;
using Autodesk.Revit.DB.Events;
using Autodesk.Revit.UI;
using Autodesk.Revit.UI.Events;

namespace IfcToRvtConverter
{
    [Transaction(TransactionMode.Manual)]
    [Regeneration(RegenerationOption.Manual)]
    [Journaling(JournalingMode.NoCommandData)]
    public sealed class IfcToRvtConverterApplication : IExternalApplication
    {
        private ControlledApplication mControlledApplication { get; set; }

        public Result OnStartup(UIControlledApplication application)
        {
            mControlledApplication = application.ControlledApplication;
            mControlledApplication.ApplicationInitialized += OnApplicationInitialized;

            return Result.Succeeded;
        }

        public Result OnShutdown(UIControlledApplication application)
        {
            return Result.Succeeded;
        }
		
        /// <summary>
        /// The action taken on application initialization.
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="eventArgs">The event args.</param>
        private void OnApplicationInitialized(object sender, ApplicationInitializedEventArgs eventArgs)
        {
            var application = sender as Application;
            
		mControlledApplication.ApplicationInitialized -= OnApplicationInitialized;

            try
            {
                var options = new Dictionary<string, string>();
			options["Action"] = "Link";
			options["Intent"] = "Reference";
			options["DisableLogging"] = "true";

			var pathIFC = "path_to_converted_ifc_file.ifc";
			var pathRVT = "path_to_converted_ifc_file.ifc.RVT";  // <= will get this file name after successful convertion
				
			var documentBlankdummy = RevitApplication.NewProjectDocument("C:\ProgramData\Autodesk\RVT 2024\Templates\English\Construction-DefaultGBRENU.rte");

			try
			{
				var importer = Importer.CreateImporter(documentBlankdummy, pathIFC, options);
				importer.ReferenceIFC(documentBlankdummy, pathIFC); // <= plausible source of crash
			}
			finally
			{
				documentBlankdummy.Close(saveModified: false);
			}
            }
            catch (Exception ex)
            {
                // process exception
            }

            var revitCommandId = RevitCommandId.LookupPostableCommandId(PostableCommand.ExitRevit);
            if (revitCommandId != null)
                new UIApplication(application).PostCommand(revitCommandId); // <= crash happens during Revit exit
        }
    }
}

this bug was observed in revit2024.2.0 and 2024.1.1 + ifc plugin 24.2 and 24.1.1
BUT did not happen in revit2022.1.5 + ifc plugin 22.5

Revit Version

2024.2.x

IFC for Revit Addon Version

24.x.x

Windows Version

11 23H2

Aaaand.... We have result?