13 Replies Latest reply on Apr 19, 2018 11:03 AM by Jacob Corder

    Solidworks hangs in system WaitHandle after editing surface for macro feature

    Greg James

      Any tips for this problem?

       

      I'll send this to apisupport@solidworks.com

      A project for an addin to repro this issue is attached.  See README_repro_steps.txt

      The Macro Feature I've created is not doing anything, just returning from Edit(), Regenerate(), and Security().  Looks like the bug has something to do with changing the offset surface Feature that was selected when the Macro Feature was created.  Deleting the Macro Feature fixes things, in that the offset surface can be edited and updated without causing a hang.   Waiting for garbage collection in Regenerate() has no effect.

       

      -- bug description --

      An offset surface feature is selected when a C# macrofeature is created.

      If the offset surface feature is edited, or if an offset surface higher in the feature tree is edited,

      Solidworks hangs at the call stack below.  The hang occurs outside any addin code.

      Call stack:

      mscorlib.dll!System.Threading.WaitHandle.WaitAny(System.Threading.WaitHandle[] waitHandles, int millisecondsTimeout, bool exitContext) Line 454 C#

        System.dll!System.Net.TimerThread.ThreadProc() Line 707 C#

        mscorlib.dll!System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state, bool preserveSyncCtx) Line 954 C#

        mscorlib.dll!System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state, bool preserveSyncCtx) Line 902 C#

        mscorlib.dll!System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state) Line 891 C#

        mscorlib.dll!System.Threading.ThreadHelper.ThreadStart() Line 111 C#

       

      -- repro steps --

      Launch the adding by building and running from the visual studio .sln

      In Solidworks, open two_offset_surfaces.SLDPRT

      In the "C# Addin" command tab, select "Macrofeature PMP" to open the property manager page.

      Select Surface-Offset1 into the PMPage selection box.

      Hit "Create MacroFeature"

      Exit the PMPage by hitting the ok or cancel buttons.

      in the Feature Tree, select Surface-Offset1 > Edit Feature

      Modifty the offset distance and hit 'ok'.

      SolidWorks hangs.

       

      -- system details --

      Solidworks Premium 2016 x64 Edition

      SP 3.0

      Microsoft Visual Studio Professional 2013

      Version 12.0.40629.00 Update 5

      Microsoft .NET Framework

      Version 4.7.02556

        • Re: Solidworks hangs in system WaitHandle after editing surface for macro feature
          Jacob Corder

          So..

           

          the api help referencing the crash or hang on rebuild was my discovery.  it has to do with IDisplayDimensions being used.  if you aren't using IDisplayDimensions, then there is no need for you to call GC.Collect in your regeneration function.

           

          i am attempting to debug your application now.

           

           

          i dont see any code in the Regeneration method.  its literally empty.

           

          have you successfully created macrofeatures in the past? 

            • Re: Solidworks hangs in system WaitHandle after editing surface for macro feature
              Greg James

              Hi Jacob - Thanks!

              Yes, for this repro I built a new simple project and took everything out of Regenerate().  Here, Regenerate() only prints a debug message and waits for the garbage collection.  My full fledged addin does a lot more, but that's not needed to repro the bug.

               

              One basic use for my addin and the macrofeature is to collect a group of surfaces.  Other code outside the macrofeature does work or writes stuff based on the collection.  In the past, I've used an Attribute for this.  It's a surprise that something about the selection set for the macro feature data causes a hang.

               

              I've created macrofeatures based on the api / sdk samples, and those are fine.  None of them have surfacebodies in the selection set though =/

            • Re: Solidworks hangs in system WaitHandle after editing surface for macro feature
              Jacob Corder

              ok. so this was kind of odd.

               

              i added a macrofeature, but it didnt ever communicate to the COMServer. 

              so i added another.  at that point the first macrofeature had a serious playback error, but the ones i added after were all fine.  they didnt care if i edited the surfaces

               

              i however am not able to get the system to crash. 

               

              trust me that means nothing when it comes to macrofeatures. 

               

              the issue is that your comserver is not being found on the first macrofeature

               

              i am only seeing 3 regenerations being called to the comserver when rebuild is being called.

              Repro MacorFeature1 never rebuilds.

               

              there is something odd with the first feature created during the first session .  i have added

                    // Default constructor

                      public MyMacroFeature() {

                          Console.WriteLine("Macrofeature Instantiated");

                      }

              at the top so you can see when the COMServer is being created.

               

              it is being created when the first call to InsertMacroFeature3 is executed like normal. 

               

              are you using DisplayDimensions in your macrofeatures?

               

              i am testing on 2018 SP1

               

              you will probably have to send me your actual code.  feel free to pm it to me.  trust me, when it comes to macrofeatures, i have 5 years of constant suffering associated with them. 

               

               

              i wont be able to help much until monday. 

                • Re: Solidworks hangs in system WaitHandle after editing surface for macro feature
                  Greg James

                  > the issue is that your comserver is not being found on the first macrofeature

                  Wow - good find.  How did you discover this?  Some Visual Studio tool?

                  Code should be all there in the top folder out of the .zip.  My class derived from ISwComFeature is in MyMacroFeature.cs

                      [System.Runtime.InteropServices.ComVisibleAttribute(true)]

                      public class MyMacroFeature : ISwComFeature

                   

                  It's declared like that, but I'm not doing anything to register the class, because I haven't found any docs that say I need to.... and because I'm not used to this COM / Windows registry business.  I figure that Solidworks would do what it needs to inside

                              IFeature lsFeature = fm.InsertMacroFeature3(

                                  "Repro MacroFeature",                                       // base name

                                  "sldw_hang_after_macrofeature_regenerate.MyMacroFeature",   // ProgId

                  to get the bits to the right place.

                   

                    • Re: Solidworks hangs in system WaitHandle after editing surface for macro feature
                      Jacob Corder

                      Ok so in the registry the class is registered in classroom clsid. The implementation of ISwComFeature must register the class because for years I never ensured that the registry was correct. If you add a key in local machine software solidworks solidworks xxxx macrofeatures it does use this to get the current version (we could care less about that btw)

                       

                      In classroot clsid ( your guid) inprocserver you will have a few entries. One they points to the file location or your DLL.  If you put your comserver in the solidworks running directory or in the Global access cache GAC  it will find it there first.

                       

                      I will find out monday why it might not be working.

                       

                      Try this.  In .net you call createobject (comserver nAME)  it will create it.  Then the first macrofeature will probably work.

                       

                      So when connecttosw is called

                       

                      Add  createobject(yourcomservrname)

                       

                      Also after you call createmacrofeature3

                       

                      Get the macrofeaturedata and check if programid doesn't equal your comserver name. If it doesn't then set it to your comserver name.

                       

                      The weirdest think is that normally you get an error in the feature after a failed rebuild.

                  • Re: Solidworks hangs in system WaitHandle after editing surface for macro feature
                    Greg James

                    This also repros in Solidworks 2018 SP1.

                    Issue is being tracked as SPR 1072396.

                    • Re: Solidworks hangs in system WaitHandle after editing surface for macro feature
                      Emerson Bottero

                      Could You Share a working example of Macro Feature? I'm really struggling here and I can't even make my property manager page show when editing a Macro Feature. I downloaded this but it never call a PMP on edit.