Skip to content

Type safe API, version 2.0.0, tests and CI - #11

Merged
damiles merged 7 commits into
masterfrom
ci
Nov 25, 2026
Merged

damiles merged 7 commits into
masterfrom
ci

Conversation

@damiles

@damiles damiles commented Nov 24, 2026 •

Copy link
Copy Markdown
Owner

Summary

Point 4 of the code review: make the public API type safe and give clear ownership to objects created by the library. It also adds automated tests and CI, which validate all the changes.

Typed pointers instead of void*

  • GLFW windows/cursors and NanoVG contexts use forward declared types (GLFWwindow*, NVGcontext*), headers still do not include GLFW or NanoVG
  • GLFW callbacks are registered with their real signatures instead of casting function pointers
  • setExternal2DDraw passes NVGcontext*; existing functions taking void* still work

const cv::Mat& in image and plot APIs

  • imshow, plot2D, plot3D and OGUIImageArea::setImage take const cv::Mat& (data is copied as before)
  • The pointer versions remain as [[deprecated]] overloads, so imshow("x", &frame) keeps compiling with a warning
  • OGUIPlotArea / OGUI3D constructors and replot take const cv::Mat& directly
  • Requires C++14 (for [[deprecated]])
  • Examples, README and hello world docs use the new API

Ownership

  • Virtual destructors in OGUIArea and OGUIWidget
  • OGUIWindow owns its main layout and file browser, OGUICVWindow owns the areas it creates, the file browser owns its file lists (std::unique_ptr). User created areas and widgets are still owned by the user

Memory bugs found on the way (AddressSanitizer)

  • OGUIFile::getPreview returned a pointer into a local Mat already released (heap-use-after-free on every image preview)
  • Destroying a window called free() on the static embedded fonts (nanovg was told to own them)
  • The file browser leaked the file list on every folder change and used a file after releasing its list

File browser errors

  • Do not exit the program when /proc/mounts can not be read, close the folder on read errors and remove the debug new line printed for each file

Version 2.0.0

  • Source compatible for normal usage, but not ABI compatible with previous builds (signatures and vtables changed), so the version and SOVERSION are now 2 (libOpenCVGUI.so.2)

Tests and CI

  • test_render draws images, every plot type, widgets and progress from the process thread and reads the framebuffer: image colors must be right and the 3D surface must write depth
  • test_dialogs checks that popup and file browser return in the UI thread and release the process thread when the window is closed
  • GitHub Actions on Ubuntu 24.04 with Xvfb and Mesa: release with examples, static library, bundled GLFW, AddressSanitizer + UBSan and ThreadSanitizer; it also installs the library and builds an application with find_package(OpenCVGUI 2.0)
  • Tests are built with -DOGUI_BUILD_TESTS=ON

imshow with 4 channel images (bug found by the tests, also in master)

  • 4 channel images were used as RGBA, so blue and red were swapped for BGRA images; now they are converted from BGRA like OpenCV does
  • Images that are not 8 bit or have 2 channels print an error instead of uploading wrong data

Notes

  • Static library with bundled GLFW can not be installed yet (the exported target needs glfw), it will be fixed with the Python wheel work
  • docs/docs/api.md is generated by Doxygen and still shows the old signatures, it needs to be regenerated

Test plan

  • Builds with no errors or warnings; old pointer calls produce deprecation warnings only
  • All examples start and keep running (camera, 3D, test video)
  • ASan test: create a window with image, 2D and 3D plots, draw frames and delete it, no errors and no leaks reported
  • ASan: file preview read is a heap-use-after-free on the previous commit and clean on this branch; unreadable images return NULL
  • Tests fail when the 3D draw is disabled or BGRA images are not converted (checked by breaking the code)
  • Locally: tests pass with release, static library, ASan + UBSan and TSan builds, with no sanitizer reports; installed package used from a separate project (shared and static)
  • All CI jobs pass, bundled GLFW only checked in CI (no Xinerama headers locally)
  • File browser in a nested X server: image preview, unreadable image, enter and leave folders, Accept returns the path and Close returns an empty string

🤖 Generated with Claude Code

David Millan Escriva and others added 7 commits November 24, 2026 11:58
Public headers used void* for GLFW windows/cursors and NanoVG contexts to
avoid including their headers, which needed casts everywhere and cast
GLFW callbacks to other function pointer types. Forward declare the
structs instead, so headers still do not depend on GLFW or NanoVG.

- OGUIWindow::glfw_window, vg and cursors are typed pointers
- GLFW callbacks are registered with their real signatures
- Drawing helpers, OGUIFile, timeline and perf graph take NVGcontext*
- setExternal2DDraw passes NVGcontext*, functions taking void* still work

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
imshow, plot2D, plot3D and setImage took void* or Mat*, losing type
checking. They now take const cv::Mat& (data is copied as before) and
const references for strings and labels.

The pointer versions are kept as deprecated overloads so existing code
keeps compiling with a warning. OGUIPlotArea and OGUI3D constructors and
replot take const cv::Mat& directly. Requires C++14 for [[deprecated]].

Examples, README and hello world docs use the new API.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Objects created by the library were allocated with new and never
released. User created areas and widgets are still owned by the user.

- Add virtual destructors to OGUIArea and OGUIWidget
- OGUIWindow owns its main layout and file browser
- OGUICVWindow owns the form, layouts and areas created by imshow/plots
- The file browser owns its file lists, folder changes no longer leak and
  no longer use a file after its list is released
- OGUIFile keeps its preview in a Mat, it returned a pointer to a local
  Mat already released (heap-use-after-free), and returns NULL when the
  image can not be read instead of throwing
- Do not let nanovg free the embedded fonts, destroying a window called
  free() on static data

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- Do not exit the program when the mount list can not be read
- Close the folder when a file can not be read and report errors to stderr
- Show the requested path when it can not be resolved
- Remove the debug new line printed for each file

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The API changes are source compatible but not ABI compatible, the new
SOVERSION makes applications built with 1.x fail to load instead of
crashing.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
imshow used 4 channel images as RGBA, so blue and red were swapped for
BGRA images loaded or created with OpenCV. Images that are not 8 bit or
have 2 channels were uploaded with a wrong size or no data, now they
print an error and are ignored.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- test_render draws images, every plot type, widgets and progress from
  the process thread and reads the framebuffer to check the image colors
  and the 3D surface depth
- test_dialogs checks that popup and file browser return in the UI
  thread and release the process thread when the window is closed
- CI on Ubuntu 24.04 with Xvfb and Mesa: release with examples, static
  library, bundled GLFW, AddressSanitizer + UBSan and ThreadSanitizer
- Install the library and build an application with find_package
- Tests are built with -DOGUI_BUILD_TESTS=ON

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@damiles
damiles merged commit 84d1e78 into master Nov 25, 2026
5 checks passed
@damiles
damiles deleted the ci branch November 25, 2026 10:47
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.

1 participant