Integration into mixed C++/C# engine
Posted: 15 Feb 2025, 20:56
We are trying to integrate noesis into our engine, which has a thin C++ layer using vulkan, and a C# layer (with mostly game logic) on top. We would like to use noesis from C#, but since the core rendering code is C++, we have to implement our RenderDevice there.
Please consider the following code:
This initializes a renderer of a View with a previously constructed RenderDevice. We call this method from C#:
Sadly initialization seems to not work (the next Update-call on the view crashes with an access-violation, and if we do any other calls, e.g., renderer->GetClassType()->GetName(), we crash immediately). It seems like the pointer we are passing is not what we expected (IRenderer). We'd appreciate any help, and information whether we are approaching this the correct way (we could also use a C# RenderDevice, which just PInvokes our C++ layer, but to have C++ -> C# -> C++ transitions for every call seems wasteful).
Please consider the following code:
Code: Select all
void GrNoesis_InitRenderer(GrInstance instance, Noesis::IRenderer* renderer)
{
renderer->Init(instance.Handle->NoesisRenderDevice);
}
Code: Select all
[DllImport(LowLevelLibrary)]
private static extern void GrNoesis_InitRenderer(GrInstance instance, IntPtr renderer);
public static void GrNoesis_InitRenderer(GrInstance instance, Renderer renderer)
{
GrNoesis_InitRenderer(instance, BaseComponent.getCPtr(renderer).Handle);
}