AnsweredAssumed Answered

SOLIDWORKS Crash Using CloseAndReopen in Conjunction with EPDM

Question asked by Jim Sculley on Feb 15, 2017

I have been fighting a problem for several months with SOLIDWORKS and EPDM.  I have a fairly complex custom add-in that worked for several years with few problems.  I was making changes to improve the experience for my users and this involved using the ISldWorks::CloseAndReopen API call.  During testing I discovered that I can consistently cause a complete crash of SOLIDWORKS (see attached dump file) and I am fairly certain that the problem lies with SOLIDWORKS and not my code.  I have whittled my add-in down to a mere 223 lines of code that demonstrate the problem.  I have attached the Visual Studio project, some test files and an export of the relevant data from my test vault.


The add-in is fairly simple.  It watches for files entering a particular state.  When a file enters the state, the add-in checks to see if any open drawings are referencing the file.  If so, the ISldWorks::CloseAndReopen method is called.  Between the closing and reopening of the drawing file, the add-in will check out the part file, set a data card variable and then check the file back in.


In my vault (which is named _DEVELOPMENT), the folder structure looks like this:






The file data card EPDMCrashTestCard should be placed in the EPDMCrash folder.  The three test files (foo.sldprt, bar.sldprt and foo.slddrw) should be placed in the EPDMCrash directory and when checked in they should be added to the EPDMCrash workflow.  The add-in can be added either directly from the CEX file or the attached Visual Studio project can be compiled and added to the vault via the Administration tool.


To reproduce the crash, proceed as follows:


1.     Start SOLIDWORKS

2.    Open bar.sldprt

3.    Open foo.slddrw

4.    From the EPDM tab of the task pane, initiate a state change on foo.sldprt.  The transition name is Start


At this point, SOLIDWORKS will either crash, or the process will complete successfully but still show the annoying dialog in the attached image.  I have found no rhyme or reason as to why it crashes sometimes and not other times.  It may succeed ten times in a row and then fail ten times in a row.  I have tested on three different machines.  I have tested in Debug mode from Visual studio and it will crash.  I can say that I have never seen it fail when no other documents other than foo.slddrw were open, so it has something to do with having multiple documents open in SOLIDWORKS.  The dump file indicates that the crash always occurs at the same place:




and running the code in the Visual Studio debugger points to the following lines in winocc.cpp


BOOL CWnd::EnableWindow(BOOL bEnable)
                ASSERT(::IsWindow(m_hWnd) || (m_pCtrlSite != NULL));

                if (m_pCtrlSite == NULL)
                                return ::EnableWindow(m_hWnd, bEnable);
                                return m_pCtrlSite->EnableWindow(bEnable); //Error occurs here


This problem has brought my add-in development to a screeching halt and I have spent every spare moment for several months distilling the problem down to a simple example the reliably demonstrated the problem.  I forwarded all this to my VAR and they were able to reproduce it and submitted it to SOLIDWORKS.  It has been assigned SPR 967430, which as of SOLIDWORKS 2017 SP2 has still not been fixed.  


I'm curious if anyone else has bumped into this problem while using CloseAndReopen along with EPDM and more importantly, if you are using CloseAndReopen with EPDM and aren't seeing this problem, what's your secret?