Community
Civil 3D Customization
Welcome to Autodesk’s AutoCAD Civil 3D Forums. Share your knowledge, ask questions, and explore popular AutoCAD Civil 3D Customization topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

GetIUnknownFromObjectId crash

0 REPLIES 0
Reply
Message 1 of 1
qa1kallocstudios
78 Views, 0 Replies

GetIUnknownFromObjectId crash

Hello,

 

If someone can help us with the proper use of ObjectPropertyManagerPropertyUtility.GetIUnknownFromObjectId inside Civil3D plugin since we are getting a random crash on exit. We can reduce that randomness by and have it crash more consistently when we call the below function in a loop 50 times.

 

using AcDb = Autodesk.AutoCAD.DatabaseServices;
using AcadEntity = Autodesk.AutoCAD.DatabaseServices.Entity;

AcDb.DBObject dbObj = trans.GetObject(m_ObjectId, AcDb.OpenMode.ForRead, true);
AcadEntity entity = dbObj as AcadEntity;
...

 public static bool GetOPMProperties(AcDb.Entity entity, Transaction trans )
 {
    IntPtr pUnk = ObjectPropertyManagerPropertyUtility.GetIUnknownFromObjectId(entity.Id);                
    if (pUnk != IntPtr.Zero)
    {
        // The below call would cause a crash due to System.AccessViolationException: Attempted to read or write protected memory.
        using (CollectionVector properties = ObjectPropertyManagerProperties.GetProperties(entity.Id, false, false))
        {
            ; // ....
        }
        
        int count = Marshal.Release(pUnk);
        
        // In a loop that call this function 50 times
        /* 29172 is the entity's Id Handle Value. count is the count got back from Marshal.Release(...)
        29172 count=0
        29172 count=0
        29172 count=-1073741823
        29172 count=0
        29172 count=-1073741823
        29172 count=0
        29172 count=0
        29172 count=0
        .... 
        
        29143 count=0
        29143 count=0
        29143 count=-1073741823
        29143 count=-1073741823
        29143 count=-1073741823
        29143 count=-1073741823
        29143 count=-1073741823
        29143 count=-1073741823
        29113 count=0
        29113 count=0
        29113 count=0
        29113 count=0
        29113 count=0
        29113 count=0
        29113 count=0
        29113 count=0
        Exception thrown: 'System.AccessViolationException' in acmgd.dll
        An unhandled exception of type 'System.AccessViolationException' occurred in acmgd.dll
        Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
        */
    }
 }

 

Now if we changed to the below call that is asked to pass-in an object we don't get crash, but we don't get a lot of properties since GetIUnknownFromObject would return null when
ObjectPropertyManagerPropertyUtility.ObjectSupportsNonDBResidency(entity) return false

 

public static bool GetOPMProperties_NonCrashing(AcDb.Entity entity, Transaction trans )
 {
    IntPtr pUnk = ObjectPropertyManagerPropertyUtility.GetIUnknownFromObject(entity, false);                
    if (pUnk != IntPtr.Zero)
    {
        using (CollectionVector properties = ObjectPropertyManagerProperties.GetProperties(entity, false, false))
        {
            ; // ....
        }
        
        int count = Marshal.Release(pUnk);
    }
 }

 

So what does ObjectPropertyManagerPropertyUtility.ObjectSupportsNonDBResidency(entity) mean, and how can I get it such that GetIUnknowFromObject would non-null pUnk?

Thanks for the help!

Tags (1)
Labels (1)
  • API
0 REPLIES 0

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Rail Community


 

Autodesk Design & Make Report