Skip to content

ofFbo: report a forgotten end() when the frame ends - #8631

Open
danoli3 wants to merge 1 commit into
openframeworks:masterfrom
danoli3:fbo-bind-stack
Open

danoli3 wants to merge 1 commit into
openframeworks:masterfrom
danoli3:fbo-bind-stack

Conversation

@danoli3

@danoli3 danoli3 commented Oct 30, 2026

Copy link
Copy Markdown
Member

Summary

finishRender() cleared the framebuffer stack at the end of every frame. The next ofFbo::end() then logged:

[ error ] unbalanced fbo bind/unbind binding default framebuffer

even when the window was already bound. A real forgotten end() was only reported on the following frame. The same path is in ofGLRenderer and ofGLProgrammableRenderer. bind() also returned early when an ofFbo was bound onto itself, so the matching end() under-popped the stack.

Both renderers now share one stack in ofFramebufferBinding.h:

  • A matching begin() / end() inside the frame is silent. The window entry pushed by startRender() stays until finishRender().
  • A forgotten end() warns once when the frame ends, with the framebuffer id that was still bound, and binds the window again. A later end() stays quiet.
  • An extra end() while only that window entry is left warns once and does not pop it.
  • Binding an ofFbo onto itself still warns, and still pushes, so its end() pops the same entry.
  • startRender() binds the window framebuffer, so the GL binding matches the id the stack records.

The check at the end of the frame uses the bound id, not stack.back(). After begin() from the window the stack is [window, window] while the ofFbo is current, so back() == window would miss a forgotten end().

Fixes #8564

Test

tests/gl/fboBindStack runs the stack with no GL context (balanced pair, forgotten end(), extra end(), begin/end outside a frame, self-bind, nested ofFbos).

Local macOS makefile build of that test:

[ notice ] framebuffer bind stack passed
[ notice ] 1/1 tests passed

finishRender() cleared the framebuffer stack every frame, so a later
end() logged "unbalanced fbo bind/unbind" even when the window was
already bound. Warn at the end of the frame if an ofFbo is still
bound, and keep a matching begin()/end() quiet.

A begin() that binds an ofFbo onto itself still pushes, so its end()
pops the same entry. Both GL renderers share the stack rules.
@danoli3

danoli3 commented Oct 31, 2026

Copy link
Copy Markdown
Member Author

This is an interesting way to handle FBO issues if detected by using fbo binding deque.

I had applied similar fixes for fbo textures binding in unity many years ago after leaks were detected in production game.

Code assisted with Grok for this one with my code examples linking to initial reported issue

@danoli3 danoli3 added this to the 0.13.0 milestone Oct 31, 2026
danoli3 added a commit to danoli3/openFrameworks that referenced this pull request Oct 31, 2026
openframeworks#8631 is still open, so the 0.12.2 summary keeps merged changes only.
danoli3 added a commit that referenced this pull request Nov 1, 2026
* CHANGELOG: main changes since 0.12.1 for 0.12.2

Grouped like earlier releases (core, gl, graphics, utils, addons, libraries; linux, windows, macos / ios / tvos, android, emscripten, makefiles), each linked to its PR. The full commit list is added at release.

* CHANGELOG: changes merged since Oct 27 (packages, nightly, apothecary pin, Emscripten 6.0.13, ccache)

* CHANGELOG: CMake, Android NDK r30, and merges since Oct 30

Adds the CMake build, moves Android from NDK r29 to r30, and notes FreeImage 3.19.28, the VS Code project generator flag, iOS / tvOS ccache, GLFW window focus, and CI failing when an example build fails.

* CHANGELOG: Debian installs x11proto-dev

Notes #8630, which fixes the Debian 13 install stop in #8481.

* CHANGELOG: ofFbo end() is reported when the frame ends

* CHANGELOG: add the 0.12.2 banner

* CHANGELOG: packages bundle the projectGenerator nightly

* CHANGELOG: drop the unmerged ofFbo note

#8631 is still open, so the 0.12.2 summary keeps merged changes only.

* CHANGELOG: add the 0.12.2 commit list

Commits from 0.12.1 (1019e6a) through master (761df7c), ancestry-path,
in the same one-line format as 0.12.1.

* CHANGELOG: 0.12.2 list with one described entry per pull request

The 0.12.2 list had 208 lines: every commit of every merged branch ("no message", "Windows", "curl debug"), merge commits next to the commits they merged, and each Emscripten, submodule and oF Menu version bump separately. It now has one entry per pull request merged into master since 0.12.1 (first-parent history, rebase-merged commits under their pull request), each with what it does, and the repeated version bumps as one entry each: Emscripten 4.0.4 -> 6.0.13, the submodule updates, oF Menu 0.3.0 -> 0.4.3, Android NDK r29 -> r30, ccache, GitHub Actions and the nightly fixes.
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.

ofFbo::end() logs a false "unbalanced fbo bind/unbind" error when finishRender() clears the framebuffer stack

1 participant