- Posts: 5
- Joined: Fri Aug 13, 2021 2:15 pm
- Real Name: Michal Zahradnik
Hello, I was trying to render preview using SharpDx library and CDeckLinkGLScreenPreviewHelper. I tried two approaches to display preview but none of them was successful. I already made working example using DX9 but I wanted to try OpenGL as well.
I am using WPF in .NET 6. Problem seems to be in threading apartments. Since but I do not know how to deal with it yet and what is correct way so I am gently asking for some help or references. I am also providing code for mentioned approaches which are described in comments. During execution of program one of them is always commented.
I am using WPF in .NET 6. Problem seems to be in threading apartments. Since but I do not know how to deal with it yet and what is correct way so I am gently asking for some help or references. I am also providing code for mentioned approaches which are described in comments. During execution of program one of them is always commented.
- Code: Select all
void IDeckLinkScreenPreviewCallback.DrawFrame(IDeckLinkVideoFrame theFrame)
{
if (openGl != null && openGlInitialized)
{
// 1. Approach
// If I create helper on UI thread and call glHelper.SetFrame(theFrame); here, I get exception:
// Unable to cast COM object of type 'System.__ComObject' to interface type 'DeckLinkAPI.IDeckLinkGLScreenPreviewHelper'
this.Dispatcher.Invoke(new Action(() =>
{
// If I create helper on UI thread and set frame here I get:
glHelper.SetFrame(theFrame); //System.InvalidCastException: 'Specified cast is not valid.'
}));
/////////////////////////////////////////////////////////////////////////////////////////////////////////
// 2. Approach
glHelper = new CDeckLinkGLScreenPreviewHelper();
openGl.RenderContextProvider.MakeCurrent();
glHelper.InitializeGL(); // this will fail with error:
// Exception thrown at 0x00007FFF81641F2D (vcruntime140.dll) in VideoDirector.Wpf.exe: 0xC0000005:
// Access violation reading location 0x0000000000000000.
Marshal.ReleaseComObject(glHelper);
}
Marshal.ReleaseComObject(theFrame);
}