.NET

.NET

Reply
Contributor
jon-p
Posts: 18
Registered: ‎01-04-2013
Message 1 of 9 (324 Views)
Accepted Solution

custom code failure in release mode

324 Views, 8 Replies
01-14-2014 09:22 AM

Hi.  I have a very specific issue where our code fails only when compiled without "Enable Optimizations" checked in advanced compile options in vs 2012.  However, the code works fine when the flag is unchecked.  The code also works on other layers in other drawings.  I'm looking for assistance to either find the issue with the layer in question, or figure out why autocad blows up when my code is in release mode.

 

Repro Steps:

download code

open in vs 2012

open project properties

open compile tab

click Advanced Compile Options

check enable optimizations

Save

Compile project

Open Autocad

netload copylayerreleasemode.dll

open enableoptimizationtest.dwg

run command LYAPTEST

observe error: FATAL ERROR unhandled access violation reading 0xbb0352a8 Exception at 8a87e7c9h

 

Additional Information:

Acad Version = 2012

When running sysinternals dbgview, i observe the following:

[5608] Error -
[5608] ReadProcessMemory failed while trying to read PebBaseAddress
[5608] 
[5608] Error -
[5608] Failed to read the peb from the process

 

I've attached the code, the dwg, screenshot of the error message, and dump file from autocad. 

Hi Jon,

 

After testing the code in release mode in various AutoCAD versions, I find the crash only in AutoCAD 2012. Both AutoCAD 2013 and 2014 versions require the .Net framework 4.0 and the sample code worked ok in the release mode.

 

In AutoCAD 2012, if the "IDMap" is disposed, then it worked in Release mode too.

 

//... Other code

IDMap.Dispose()

End If
myTrans.Commit()
End Using

 

Sorry, I am not aware of the reason why the dispose would be necessary especially when the optimisations are enabled.

 

Please try this and see if it works at your end.

 

Regards,

Balaji

 

 

Valued Mentor
DiningPhilosopher
Posts: 370
Registered: ‎05-06-2012
Message 2 of 9 (295 Views)

Re: custom code failure in release mode

01-14-2014 02:52 PM in reply to: jon-p

From your code:

 

For Each thisPair As IdPair In IDMap
   If thisPair.IsCloned Then
      Select Case thisPair.Value.ObjectClass.Name
          Case "AcDbDictionary", "AcDbBlockRepresentationData", "AcDbXrecord", "AcDbSpatialFilter"
								'Do nothing here
          Case Else
              Dim myEnt As Entity = CType(myTrans.GetObject(thisPair.Value, OpenMode.ForWrite, False, True), Entity)
              myEnt.LayerId = DestID
      End Select
   End If
Next

While I didn't try to repro your problem, based on the code above, I am guessing that there's a null

reference exception when the object is not an Entity, nor any of the types that your code erroneously

checks for explicitly. The Case test that compares the ObjectClass.Name to one of several known types

is a problem, because if the object is not one of those types, that does not mean it is an Entity.

 

I would get rid of the Select Case entirely and Just use TryCast() to try to cast the object to an Entity,

and if the result is null, skip it and go to the next object.

 

 

Contributor
jon-p
Posts: 18
Registered: ‎01-04-2013
Message 3 of 9 (292 Views)

Re: custom code failure in release mode

01-14-2014 03:04 PM in reply to: DiningPhilosopher

DiningPhilosopher,

Thanks for the suggestion.  I changed the code that you called out to the following:

For Each thisPair As IdPair In IDMap
	If thisPair.IsCloned Then
		Dim myent As Entity
		myent = TryCast(myTrans.GetObject(thisPair.Value, OpenMode.ForWrite, False, True), Entity)
		If myent IsNot Nothing Then
			myent.LayerId = DestID
		End If
	End If
Next

However, the issue still persists. If you have any further insights, please let me know.

Thanks,

Jon

*Expert Elite*
Hallex
Posts: 1,569
Registered: ‎10-08-2008
Message 4 of 9 (276 Views)

Re: custom code failure in release mode

01-14-2014 06:52 PM in reply to: jon-p

Try use OpenMode.ForRead instead:

For Each thisPair As IdPair In IDMap 
If thisPair.IsCloned Then 
Dim myent As Entity myent = TryCast(myTrans.GetObject(thisPair.Value, OpenMode.ForRead, False, True), Entity) 
If myent IsNot Nothing Then
myent.UpgradeOpen()
myent.LayerId = DestID 
End If 
End If 
Next

 

_____________________________________
C6309D9E0751D165D0934D0621DFF27919
Contributor
jon-p
Posts: 18
Registered: ‎01-04-2013
Message 5 of 9 (259 Views)

Re: custom code failure in release mode

01-15-2014 06:44 AM in reply to: Hallex

Hallex,

Thanks for your reply.  I tried making that modification and no luck.  It still errors when built in release mode.

-Jon

Contributor
jon-p
Posts: 18
Registered: ‎01-04-2013
Message 6 of 9 (252 Views)

Re: custom code failure in release mode

01-15-2014 07:24 AM in reply to: jon-p

Sorry, just saw a typo in the first section.  it should read, "I have a very specific issue where our code fails only when compiled with "Enable Optimizations" checked in advanced compile options in vs 2012."

*Expert Elite*
Hallex
Posts: 1,569
Registered: ‎10-08-2008
Message 7 of 9 (247 Views)

Re: custom code failure in release mode

01-15-2014 07:33 AM in reply to: jon-p
Sorry I can't help, some problems on my own story
Hope TT could help you further
_____________________________________
C6309D9E0751D165D0934D0621DFF27919
ADN Support Specialist
Balaji_Ram
Posts: 749
Registered: ‎03-21-2011
Message 8 of 9 (177 Views)

Re: custom code failure in release mode

01-20-2014 02:09 AM in reply to: jon-p

Hi Jon,

 

After testing the code in release mode in various AutoCAD versions, I find the crash only in AutoCAD 2012. Both AutoCAD 2013 and 2014 versions require the .Net framework 4.0 and the sample code worked ok in the release mode.

 

In AutoCAD 2012, if the "IDMap" is disposed, then it worked in Release mode too.

 

//... Other code

IDMap.Dispose()

End If
myTrans.Commit()
End Using

 

Sorry, I am not aware of the reason why the dispose would be necessary especially when the optimisations are enabled.

 

Please try this and see if it works at your end.

 

Regards,

Balaji

 

 



Balaji
Developer Technical Services
Autodesk Developer Network

Contributor
jon-p
Posts: 18
Registered: ‎01-04-2013
Message 9 of 9 (159 Views)

Re: custom code failure in release mode

01-20-2014 06:39 AM in reply to: Balaji_Ram
Worked great. Thanks for your help Balaji.
Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Announcements
Do you have 60 seconds to spare? The Autodesk Community Team is revamping our site ranking system and we want your feedback! Please click here to launch the 5 question survey. As always your input is greatly appreciated.