Skip to content

MacOS: fix render issue in obs-32 branch - #742

Merged
sandboxcoder merged 2 commits into
obs_merge_32.1.1from
rno/fix-iosurface
Jul 14, 2026
Merged

MacOS: fix render issue in obs-32 branch#742
sandboxcoder merged 2 commits into
obs_merge_32.1.1from
rno/fix-iosurface

Conversation

@sandboxcoder

@sandboxcoder sandboxcoder commented Jun 17, 2026

Copy link
Copy Markdown

Description

  • Fix issue in Obs-32 branch where create_iosurface uses kIOSurfaceIsGlobal: YES but then immediately called CFRelease causing IOSurfaceLookup in both write_iosurface and node-window-rendering to return NULL.
  • Fix pre-existing issue (while we are in here) where we'd have OpenGL glClear errors being sent to the logs. Add checks for 0x0 sized buffer.
  • Add optional DEBUG_WRITE_IOSURFACE code path which will dump the IOSurface contents into a .png file which can be helpful determining if backend is properly rendering (because if we have pixels, then problem is upstream in NWR/Desktop).

Motivation and Context

Depends on this PR: #734. Fix rendering issue for macOS in obs-32 branch

How Has This Been Tested?

Verified I see images rendered during dual output etc on Streamlabs Desktop in obs_merge_32.1.1 locally

Types of changes

  • Bug fix (non-breaking change which fixes an issue)

Checklist:

  • My code has been run through clang-format.
  • I have read the contributing document.
  • My code is not on the streamlabs branch.
  • The code has been tested.
  • All commit messages are properly formatted and commits squashed where appropriate.
  • I have included updates to all appropriate documentation.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR targets macOS OpenGL rendering by keeping the created IOSurfaceRef alive (instead of releasing it immediately) so IOSurfaceLookup-based consumers don’t see NULL, and by tightening present/readback behavior to avoid benign GL errors.

Changes:

  • Persist and manage the lifetime of the created IOSurfaceRef (store on swapchain/windowinfo; release on teardown).
  • Adjust swapchain/present readiness logic and add optional debug IOSurface dumping support.
  • Remove UniformTypeIdentifiers dependency in the IOSurface debug helper (use "public.png" UTI string).

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
libobs-opengl/IOSurfaceHelper.m Removes UTType dependency and updates PNG type usage for debug image export.
libobs-opengl/gl-cocoa.m Stores/releases IOSurfaceRef, updates swapchain load/present readiness, and changes IOSurface readback path.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread libobs-opengl/IOSurfaceHelper.m
Comment thread libobs-opengl/gl-cocoa.m Outdated
Comment thread libobs-opengl/gl-cocoa.m Outdated
@sandboxcoder
sandboxcoder marked this pull request as draft June 17, 2026 23:16
@sandboxcoder sandboxcoder changed the title MacOS: fix render issue MacOS: fix render issue in obs-32 branch Jun 17, 2026
@sandboxcoder
sandboxcoder requested a review from Copilot June 18, 2026 15:40

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.

Comment thread libobs-opengl/gl-cocoa.m Outdated
Comment thread libobs-opengl/gl-cocoa.m Outdated
Comment thread libobs-opengl/gl-cocoa.m Outdated

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated no new comments.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

Comments suppressed due to low confidence (1)

libobs-opengl/gl-cocoa.m:723

  • If IOSurfaceCreate fails, this function still returns swap->wi->surfaceID, which may be a stale, non-zero ID from a previous successful call. That makes failure indistinguishable from success for callers. Return 0 on failure and only update swap->wi->surfaceID when a new surface was actually created.
    IOSurfaceRef surfaceRef = IOSurfaceCreate((CFDictionaryRef) surfaceAttributes);
    if (surfaceRef) {
        swap->wi->surfaceID = IOSurfaceGetID(surfaceRef);
        if (swap->wi->surfaceRef) {
            CFRelease(swap->wi->surfaceRef);
            swap->wi->surfaceRef = NULL;
        }
        swap->wi->surfaceRef = surfaceRef;
    } else {
        blog(LOG_ERROR, "create_iosurface IOSurfaceCreate failed");
    }

    [surfaceAttributes release];

    return swap->wi->surfaceID;
}

Comment thread libobs-opengl/IOSurfaceHelper.h Outdated

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

Comment thread libobs-opengl/gl-cocoa.m
Comment thread libobs-opengl/gl-cocoa.m Outdated
@sandboxcoder
sandboxcoder marked this pull request as ready for review June 18, 2026 16:44
* Fix issue in Obs-32 branch where create_iosurface uses
kIOSurfaceIsGlobal: YES but then immediately called CFRelease causing
IOSurfaceLookup in both write_iosurface and node-window-rendering to
return NULL.
* Fix pre-existing issue while we are in here where we'd have
glClear errors being sent to the logs (we still rendered, but it
polluted the logs and wasn't good practice). Add checks for 0x0 sized
buffer etc.
* Add optional DEBUG_WRITE_IOSURFACE code path which will dump the
IOSurface contents which can be helpful determining if backend is
properly rendering (because if we have pixels, then problem is upstream
in NWR/Desktop).
Comment thread libobs-opengl/gl-cocoa.m
}
swap->wi->surfaceRef = surfaceRef;
} else {
swap->wi->surfaceID = 0;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When IOSurfaceCreate fails, this clears surfaceID but leaves the previous surfaceRef alive. Since write_iosurface now gates on surfaceRef, a failed create or 0x0 resize can still keep writing into the stale IOSurface even though callers see ID 0. Please release/null surfaceRef here too, and ideally explicitly return early for width == 0 || height == 0.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought bout that but received this defect from copilot which made me think it's better to keep the existing one? Updated in 6c47cae, early reject if width/height is 0

@sandboxcoder
sandboxcoder merged commit 03c6e91 into obs_merge_32.1.1 Jul 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants