iOS/JSC: getUserMedia camera VideoTexture never renders — NativeVideo::SetSrcObject rejects MediaStream (InstanceOf fails across napi/JSC)

Open
#1,768 0 comments 1 reaction 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
48/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Quiet
Tech stack
cpp, ios, javascript

Research direction

Start with Apps/Playground on iOS using the cameraTexture path in experience.js, then inspect NativeVideo::SetSrcObject in Plugins/NativeCamera/Source/NativeVideo.cpp and trace the failing InstanceOf check on JavaScriptCore. Done means the genuine getUserMedia MediaStream is accepted, the playing event occurs, CreateFromStreamAsync resolves, and the camera VideoTexture renders on iOS.

Written by the indexing model from the issue text.

Description

Summary

On iOS (JavaScriptCore), NativeVideo::SetSrcObject rejects the MediaStream returned by navigator.mediaDevices.getUserMedia, so VideoTexture.CreateFromStreamAsync never renders the camera feed. Camera capture works (AVCaptureSession runs, frames flow), but no texture ever updates.

Environment
  • Babylon Native master @ 64f545de; Babylon.js 9.9.1 (UMD babylon.max.js)
  • iOS 26.5, iPhone 15 Pro Max (device), Xcode 26
  • Repro: Apps/Playground iOS with the cameraTexture path in experience.js enabled
Root cause

Plugins/NativeCamera/Source/NativeVideo.cpp, SetSrcObject:

if (value.IsNull() || value.IsUndefined() ||
    !value.As<Napi::Object>().InstanceOf(MediaStream::GetConstructor(env)))
{
    // reject: m_streamObject cleared, m_isReady = false
    return;
}

getUserMedia creates the stream via MediaStream::GetConstructor(env).New({}), and SetSrcObject checks InstanceOf(MediaStream::GetConstructor(env)) against the same cached constructor — yet InstanceOf returns false across the napi/JavaScriptCore boundary for the genuine MediaStream object.

On-device trace (instrumented):

SetSrcObject called null=0 obj=1 instanceOfMediaStream=0   <- object is a MediaStream, InstanceOf fails

Because the stream is rejected, readyState stays 0, so Babylon.js's VideoTexture.CreateFromStreamAsync never gets the "playing" event (its NativeVideo::Play only fires "playing" when a stream is set), the returned Promise never resolves, the VideoTexture is never constructed, and engine.updateVideoTexture is never called.

Impact

getUserMedia + VideoTexture.CreateFromStreamAsync (camera-to-texture) is completely broken on the JSC/iOS backend.

Suggested fix

Either investigate why Napi::Value::InstanceOf fails for ObjectWrap constructors on the JSC engine, or identify the MediaStream more robustly. A pragmatic fix is to duck-type on the presence of getVideoTracks:

const bool looksLikeMediaStream =
    value.IsObject() && value.As<Napi::Object>().Get("getVideoTracks").IsFunction();
if (value.IsNull() || value.IsUndefined() || !looksLikeMediaStream) { /* reject */ }

Happy to open a PR.

Dominant language
C++
Stars
931
Forks
169
Avg merge
2d 17h
Merged PRs (30d)
66

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from BabylonJS/BabylonNative

All issues in BabylonJS/BabylonNative

Similar issues

More C++ issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.