How to set render delegate on Mac OS. Crash due to segfault

I am getting a segfault when call the execute() method on HD engine. The only weird thing I am noticing is the render delegate display name is GL instead of Metal?.

    _hgi = Hgi::CreatePlatformDefaultHgi();
    // hgi name: Metal
    std::cout << "hgi name: " << _hgi.get()->GetAPIName() << std::endl;
    _hgiDriver =  HdDriver{HgiTokens->renderDriver, VtValue(_hgi.get())};

    // current renderer plugin: HdStormRendererPlugin
    std::cout << "current renderer plugin: " << _curRendererPlugin << std::endl;
  // first task: /defaultTaskController/simpleLightTask
    std::cout << "first task: " << tasks.front()->GetId() << std::endl;

    // renderer display name: GL
    std::cout << "renderer display name: " << _renderIndex->GetRenderDelegate()->GetRendererDisplayName() << std::endl;

    // renderer display name: renderDriver
    std::cout << "renderer display name: " << _renderIndex->GetDrivers().front()->name << std::endl;
    
    // segfaults here !
    _engine.Execute(_renderIndex, &tasks);

I think for macOS/Clang, this is still an issue, the external Hgi does’t work, but only GLEngine created Hgi would work internally, because of RTTI issue according to some old posts.

I built this and it loads and displays a model from a USD file. It seems to be using Metal on MacOS but I am not sure if this is via OpenGL emulation

IImGuiHydraEditor uses Metal directly, not GL emulation, nor the GL/OpenGL interop implemented by the imaging GL engine.

The platform hgi is created here:

Actually I’d like to try 3 Hgi backends on macOS, to make comparison, but it seems that only Metal is possible.

You can definitely access the Metal renderer without the GL interop.

But if you’re looking to compare backends, you cannot compare all three on the same platform. Metal is the only option on macOS. GL and Vulkan on other platforms.

I found the problem. The HdEngine::render() seems to require a window to be initialised.

I added the following and it is no longer crashing due to segfault.

    GarchGLDebugWindow window("Hdx Test", 256, 256);
    window.Init();