.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

weird problem

4 REPLIES 4
Reply
Message 1 of 5
Anonymous
224 Views, 4 Replies

weird problem

I have a weird problem

I made a function that allows me to select all the entities on a certain layer. This function has been working perfectly for a while (I use it very often).

Today, I wrote a simple program to manipulate the text elements on a certain layer.

Every time I try to run my program, it crashes and I get the following error message:

Attempted to read or write protected memory. This is often an indication that other memory is corrupt.

The program crashes in the function to select the items mentioned above after the following line of code:

Dim bt As BlockTable = myT.GetObject(db.BlockTableId, Autodesk.AutoCAD.DatabaseServices.OpenMode.ForRead, False)

I tried to copy the text elements in a new DWG but I still get the same error message.

Any idea?
4 REPLIES 4
Message 2 of 5
cadMeUp
in reply to: Anonymous

Could you show some more of your code? You can't determine where the problem is from the one line. Maybe the whole body of code?
Message 3 of 5
Anonymous
in reply to: Anonymous

I found the problem
Message 4 of 5
Anonymous
in reply to: Anonymous

Yes, but did you find the solution?

wrote in message news:5747947@discussion.autodesk.com...
I found the problem
Message 5 of 5
Anonymous
in reply to: Anonymous

Yes

The function to select objects on a certain layer is called selectObjOnLayer.
It has to parameters: a layer name (layerName) and a collection (rtrObjIDcol), passed by reference -- the collection is used to return the objectID of all the elements on layerName. It return an error code.

I have an other function called doesLayerExist
It takes a layer name (layerName) as a parameter and it return true if the layer exist, false if the layer does not exist

selectObjOnLayer call doesLayerExist

I checked the return value of doesLayerExist this way:
if exist = false
.......myT. abort
.......myT.dispose
.......tm.dispose
.......db.dispose
end if

where:
myt is a transaction
tm is a transaction manager
db is the dwg database

I had forgot to exit the function when the layer didn't exist so it continued but myT was disposed.
This is what caused the error when I created the bt
Dim bt As BlockTable = myT.GetObject(db.BlockTableId, Autodesk.AutoCAD.DatabaseServices.OpenMode.ForRead, False)

the verification of the return value of doesLayerExist should have been something like:
if exist = false
.......myT. abort
.......myT.dispose
.......tm.dispose
.......db.dispose
.......return errCode
end if

The problem was caused by the fact that myT had been disposed before creating the BlockTable because I had forgot to exit the function when I had detected an error.

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

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost