Unhandled Exception C0000005

Unhandled Exception C0000005

Anonymous
Not applicable
1,309 Views
3 Replies
Message 1 of 4

Unhandled Exception C0000005

Anonymous
Not applicable
(Access Violation Reading 0xaa00004d)

So... I get this error when exiting AutoCAD 2010. I've narrowed it down to one specific function. If the function is run, the error gets thrown on exit - if the function does not run, there is no error. Can someone shed some light on what the heck I'm doing wrong, please? The function is intended to load a text style based on a specific shx. It does what it should do, except for the error when exiting AutoCAD.

public static void AddTextStyle(String textStyle, String shx)
{
Database db = Application.DocumentManager.MdiActiveDocument.Database;
Autodesk.AutoCAD.DatabaseServices.TransactionManager tm = db.TransactionManager;
Transaction tr = tm.StartTransaction();
TextStyleTable tst = (TextStyleTable)tm.GetObject(db.TextStyleTableId, OpenMode.ForWrite);
TextStyleTableRecord tstr = new TextStyleTableRecord();
tstr.Name = textStyle;
tstr.FileName = shx;
tst.Add(tstr);
tr.AddNewlyCreatedDBObject(tstr, true);
tr.Commit();
tr.Dispose();
tstr.Dispose();
tst.Dispose();
}
0 Likes
1,310 Views
3 Replies
Replies (3)
Message 2 of 4

norman.yuan
Mentor
Mentor
Did you implement IExtensionApplication and have code run in its Terminate() method?

Form the code you showed, you should remove the last 2 lines of "xxx.Dispose();":

tstr is the TestStyleTableRecord, which is what you need to create and add to the database and you code does that correctly. But why you dispose it?

Also, for tst, the TextStyleTable, which is part of drawing database, you did not create it, why dispose it?

While AutoCAD still work OK after running your function, the unnecessary Dispose() may seem harmless, but since the we really have no idea how Autodesk implemented Dispose() method under the hood, there may be chance something gone wrong here.

Anyway, whther the Acad exiting error is caused by it or not, the extra 2 Dispose() are redundant, to say the least.

Norman Yuan

Drive CAD With Code

EESignature

0 Likes
Message 3 of 4

Anonymous
Not applicable
I've not needed to define text styles through code, so I'm guessing
here, that it's happening because the new TextStyleTableRecord is
not being correctly initialized. Try setting the XScale property; the
FontDescriptor property, and any others whose default values are
not the same as they are in the 'standard' style, when you create it.

Text Styles you create through the UI have XData attached to them
(the FontDescriptor is stored in it). See if your new record has it
after you add it to the database. If not, that could be the problem.

If none of that works, try calling Clone() on the record for the
'Standard' text style, modify that, and append it to the table.


--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD
Supporting AutoCAD 2000 through 2010

http://www.acadxtabs.com

Email: string.Format("{0}@{1}.com", "tonyt", "caddzone");

wrote in message news:6357726@discussion.autodesk.com...
(Access Violation Reading 0xaa00004d)

So... I get this error when exiting AutoCAD 2010. I've narrowed it down to one
specific function. If the function is run, the error gets thrown on exit - if
the function does not run, there is no error. Can someone shed some light on
what the heck I'm doing wrong, please? The function is intended to load a text
style based on a specific shx. It does what it should do, except for the error
when exiting AutoCAD.

public static void AddTextStyle(String textStyle, String shx)
{
Database db =
Application.DocumentManager.MdiActiveDocument.Database;
Autodesk.AutoCAD.DatabaseServices.TransactionManager tm =
db.TransactionManager;
Transaction tr = tm.StartTransaction();
TextStyleTable tst =
(TextStyleTable)tm.GetObject(db.TextStyleTableId, OpenMode.ForWrite);
TextStyleTableRecord tstr = new TextStyleTableRecord();
tstr.Name = textStyle;
tstr.FileName = shx;
tst.Add(tstr);
tr.AddNewlyCreatedDBObject(tstr, true);
tr.Commit();
tr.Dispose();
tstr.Dispose();
tst.Dispose();
}
0 Likes
Message 4 of 4

Anonymous
Not applicable
The Dispose() calls did not exist in my original code. I had added them when the problem arose to see if it would fix it. Yes, I implement IExtensionApplication and a Terminate function (which currently does nothing). SDI mode was set to 1 (for another application I was developing). When I set SDI to 0, the problem went away. Given the environment this will be run in, it's fine if it only works without SDI, although it would be interesting to know why this is an issue. Edited by: fyathyrio8 on Mar 22, 2010 12:43 PM
0 Likes