locked
What are the reasons for SEHException in multi threaded DirectX code?

    Question

  • I am working with a fairly large and complicated codebase I am not familiar with, which uses DirectWritefor text rendering. I don't know whether if it matters, but this is a WinRT (Windows Store) application.

    The app is multi threaded, and some DirectX calls are done from a background (not UI) thread. All theBeginDraw and EndDraw calls are made from the UI thread, and some of the DrawText calls are made from background threads. I made sure that none of these calls overlap, and DrawText is only called between BeginDraw and EndDraw pairs.

    However, sometimes I get a SEHException when calling the DrawText method. It never happens when it is called from the UI thread, only when called from a background thread.
    This does not happen on every computer. It very often happens on some, and can not be reproduced at all on others.
    The exact message the VS Debugger says is this: "A first chance exception of type 'System.Runtime.InteropServices.SEHException' occurred in x.DLL", and it happens when I call the ID2D1DeviceContext.DrawText() function, and the debugger breaks in the d2d1.h header file at the DrawText call.

    What are the usual reasons for this (SEHException)?
    And apart from this, are there any general rules of calling DirectX functions from background threads? (I made sure that the D2D1Factory gets created with D2D1_FACTORY_TYPE_MULTI_THREADED option.)



    • Edited by MarkVincze Friday, October 05, 2012 7:55 AM
    Thursday, October 04, 2012 6:10 PM