Revit API Forum
Welcome to Autodesk’s Revit API Forums. Share your knowledge, ask questions, and explore popular Revit API topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

SEHException when calling Faces

3 REPLIES 3
SOLVED
Reply
Message 1 of 4
WouterWwts
697 Views, 3 Replies

SEHException when calling Faces

Hi, 

 

I've been stuck on this problem for a while already. Sometimes (I'll explain when it happens and how), I am getting the following exception when using 

 

face1.Intersect(face2)

 :

 

Autodesk.Revit.Exceptions.InternalException: An unexpected managed exception was thrown by internal Revit code. ---> System.Runtime.InteropServices.SEHException: External component has thrown an exception.
   at __RTDynamicCast(Void* , Int32 , Void* , Void* , Int32 )
   at Autodesk.Revit.DB.Face.getNativeObjectAsConstGFace()
   at APIGFaceTypeConverter.ManagedToNative(Face managedObj, GFace** nativeObj, ManagedToNativeParameter convParam)
   at Autodesk.Revit.DB.FaceAPIUtils.FaceXFaceIntersect(Face face1, Face face2)
   --- End of inner exception stack trace ---
   at Autodesk.Revit.DB.FaceAPIUtils.FaceXFaceIntersect(Face face1, Face face2)

 

 

The Face that is causing this problem is face2. face2 is one of many Face objects that will be checked on intersection with another face (face1: a face that is not a room face). face2 is a Face retrieved from a Room's geometry:

 

SpatialElementGeometryResults results = calculator.CalculateSpatialElementGeometry(room);

Solid roomSolid = results.GetGeometry();

foreach (Face face in roomSolid.Faces)
{
   ...

 

Each face will then be stored as a Face field, together with some other fields inside an object. At that moment, every stored face is intact with all its properties. 

 

Later in the code I am calling the Face (face2) from one of those objects. At that moment, all of face2's properties throw an SEHException. So, when using the face1.Intersect(face2) or calling any property (like (face2 as Planarface).Normal, ...), an SEHException will be thrown.

 

This exception did occur on my computer (at a different place in the code), but doesn't occur anymore. However now I'm getting this exception on a different computer. Once one exception is thrown, lots of other faces are throwing the exception too. When debugging the code using a breakpoint in the code and then removing that breakpoint and continue executing, not a single SEHException is thrown. It seems like "pausing" the code for a short while and then continueing is resolving the problem.

 

I've been looking around for this problem, and thought it had something to do with this post: http://thebuildingcoder.typepad.com/blog/2011/09/exception-on-copied-geometry.html .  However I don't think this is the problem, as the face is just stored as a field inside an object and later retrieved again from that object. It could have something to do with the garbage collecting, but I don't see why that would happen, as I'm storing a face because I want to reuse it later. I don't think a simple Face field should lose its properties just because it can.

The fact that it doesn't happen on my computer, but now does happen on another computer makes it even more strange.

 

It seems like there's something going wrong inside the API, or I am doing something wrong that I'm not aware of at the moment.

 

Any thoughts?

 

3 REPLIES 3
Message 2 of 4
arnostlobel
in reply to: WouterWwts

Hello WouterWwts,

 

Unfortunately, I am not closely familiar with this particular interface for calculating spatial geometry. I  took a brief look into the source code though to at least  get an idea about what might go wrong and why. I think I still need to ask the programmer who wrote this piece of API to get deeper understanding of details, but from what I found so far in the code it looks like the spatial geometry (the solid and its faces) are only valid  as long as:

  1. No other calculators is used
  1. And no changes are made to the document/model

 

If any of the above condition aren't met, the spatial calculator's temporary cache will be cleared up, which will also invalidate (delete) the faces of the previously calculated geometry.

 

So, if you happen to make any changes before you obtained the faces and the time you attempted to use them, the above would be the explanation of why you get an exception.

 

I'll try to find out more next week.

Arnošt Löbel
Message 3 of 4
arnostlobel
in reply to: arnostlobel

Oh, one more thing: I would also assume that if you let the spatial calculator object (the one you got the results from) go out of scope so it would be eventually destroyed by the garbage collector, that would naturally destroy the calculator's cache too, which in turn would invalidate all the face objects as well.

 

Arnošt Löbel
Message 4 of 4
WouterWwts
in reply to: arnostlobel

Thanks a lot for your reply!

 

The second condition you mentioned wasn't met in my code. That explains why a first function succeeded in calling all faces, while a second function did not: the second function indeed made changes to the document.

 

My workaround now is recalculating the geometry and faces every time the document changed. It takes a bit more time to excecute, but at least it works for now!

 

The reason why it previously worked on different pc's, but didn't work on others is probably the nature of resource handling in the API code.

 

Thanks again!

 

Wouter

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


Rail Community