BabylonJS / BabylonJS/BabylonNative

GetPlatformInfo returns null for caller-provided EGL contexts

Open
#1,853 0 comments 0 reactions 1 assignee Claimed by @bkaradzic-microsoft View on GitHub
Dominant language
C++
Stars
919
Forks
162
Avg merge
1d 15h
Merged PRs (30d)
19

Description

[Filed by Copilot on behalf of @bghgary]

## Problem

Passing a caller-created EGL context through `Graphics::Configuration::Device` renders correctly, but `Device::GetPlatformInfo().Device` returns null. D3D11, D3D12, and Metal preserve the caller-provided device through the same API.

Verified on BabylonNative `c7f7895f11262a5731ae99ba91b1618dbd09a0aa` using Linux EGL under Xvfb/Mesa: bgfx cleared the caller's pbuffer to the expected pixel, and the context remained usable after `Graphics::Device` was destroyed. Only the accessor failed.

## Cause

The pinned bgfx [EGL path](https://github.com/BabylonJS/bgfx/blob/d1b802b859689fc31beaa90396c80737abd91b6f/src/glcontext_egl.cpp#L252-L628) assigns `g_internalData.context = m_context`, but `m_context` is initialized only when bgfx creates the context. The external-context branch leaves it null. Related upstream issue [bkaradzic/bgfx#3386](https://github.com/bkaradzic/bgfx/issues/3386) tracks the same missing EGL bookkeeping for `m_display` and `m_config`.

## Test gap

`Tests.Device.cpp` verifies caller-provided device reporting and replacement, but [CMake builds it only for D3D11 and D3D12](https://github.com/BabylonJS/BabylonNative/blob/c7f7895f11262a5731ae99ba91b1618dbd09a0aa/Apps/UnitTests/CMakeLists.txt#L42-L45). Metal is covered indirectly because the macOS harness supplies a device and ExternalTexture tests consume `GetPlatformInfo().Device`. There is no EGL equivalent, and bgfx has no external-EGL-context test.

Add an OpenGL/EGL regression test that creates a caller-owned context and verifies rendering, `GetPlatformInfo()`, and caller ownership after teardown.

## Expected behavior

`GetPlatformInfo().Device` returns the context supplied through `Configuration::Device`.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.