Skip to content

fix: Windows build for sam3_image/sam3_video + close CI gap#7

Merged
PABannier merged 1 commit intomainfrom
fix/windows-build-issue-5
Apr 10, 2026
Merged

fix: Windows build for sam3_image/sam3_video + close CI gap#7
PABannier merged 1 commit intomainfrom
fix/windows-build-issue-5

Conversation

@PABannier
Copy link
Copy Markdown
Owner

Summary

Fixes #5. The four bugs @mimi3421 reported are all real, and there is a fifth finding: Windows is in CI, but the job silently skipped sam3_image / sam3_video because SDL2 was never installed on the runner, so find_package(SDL2 QUIET) returned empty and CMake dropped both GUI targets. The library and headless examples happened to be portable, so CI stayed green while the Windows GUI pipeline was broken.

Code fixes

  • sam3.cpp — the ffmpeg / ffprobe popen calls were not Windows-safe:
    • 2>/dev/null does not exist in cmd.exe → now uses NUL on Windows via a _WIN32 shim.
    • popen(cmd, "r") opens the pipe in text mode on Windows, and CRLF translation silently mangles the raw RGB byte stream from ffmpeg → now opens with "rb" on Windows.
  • examples/main_image.cpp + examples/main_video.cpp:
    • Added #define SDL_MAIN_HANDLED so SDL does not rewrite main()SDL_main() (we don't link SDL2main).
    • Replaced the GL/gl.h / OpenGL/gl3.h #ifdef block with a single #include <SDL_opengl.h>, which abstracts the windows.h prerequisite and exposes modern GL prototypes uniformly.
  • examples/third-party/CMakeLists.txt — removed IMGUI_IMPL_OPENGL_LOADER_CUSTOM. ImGui v1.91.8 uses its bundled imgl3w loader (imgui_impl_opengl3_loader.h) when no loader mode is defined. LOADER_CUSTOM was telling ImGui "the user provides GL function loading" when nothing did — Linux built by accident because libGL.so exports GL 3+ symbols at link time; MSVC's opengl32.lib does not.

CI fix (.github/workflows/ci.yml)

  • New step installs SDL2 via vcpkg on the Windows runner.
  • Windows cmake_args now passes -DCMAKE_TOOLCHAIN_FILE=C:/vcpkg/scripts/buildsystems/vcpkg.cmake -DVCPKG_TARGET_TRIPLET=x64-windows.
  • The verify step now asserts sam3_image.exe and sam3_video.exe exist on Windows, so the silent-skip regression cannot return.

Out of scope (tracked separately)

The issue also lists three side suggestions: mask-export filename collision on repeated clicks, GUI threading, and a Vulkan backend. These are unrelated to "does it build on Windows" and deserve separate issues.

Test plan

  • macOS local: sam3_image and sam3_video rebuild cleanly after the SDL_opengl.h + loader changes (verified).
  • Linux CI job still passes (the LOADER_NONE-equivalent loader change is the risky bit for Linux).
  • Windows CI job now builds sam3_image.exe and sam3_video.exe and the verify step finds them — this is the load-bearing check, because if both EXEs link, every bug in the issue is fixed at compile/link time.
  • Post-merge: @mimi3421 confirms a Windows sam3_video.exe run decodes frames without CRLF corruption (can't validate from macOS).

🤖 Generated with Claude Code

Fixes #5. The Windows job in CI was silently skipping sam3_image and
sam3_video because SDL2 was never installed on the runner, so
find_package(SDL2 QUIET) returned empty and the GUI targets were skipped.
The headless targets happened to be portable, so CI stayed green while
the GUI pipeline was broken on Windows.

Code fixes (all four confirmed in issue #5 by @mimi3421):

- sam3.cpp: ffmpeg/ffprobe popen calls were not Windows-safe. Added a
  _WIN32 shim for NUL vs /dev/null and for "rb" vs "r" popen mode.
  Without binary mode, _popen runs in text mode on Windows and CRLF
  translation silently corrupts the raw RGB stream from ffmpeg.

- examples/main_image.cpp + main_video.cpp: added SDL_MAIN_HANDLED so
  SDL does not rewrite main() to SDL_main() (we do not link SDL2main).
  Replaced the GL/gl.h / OpenGL/gl3.h ifdef block with a single
  <SDL_opengl.h> include, which abstracts the windows.h prerequisite
  and exposes modern GL prototypes uniformly across platforms.

- examples/third-party/CMakeLists.txt: removed
  IMGUI_IMPL_OPENGL_LOADER_CUSTOM. ImGui v1.91.8 ships a built-in gl3w
  loader in imgui_impl_opengl3_loader.h that is used when no loader
  mode is set. LOADER_CUSTOM was telling ImGui "the user provides GL
  loading" when nothing did; Linux built by accident because libGL.so
  exports GL 3+ symbols at link time, MSVC's opengl32.lib does not.

CI fix (.github/workflows/ci.yml):

- New step installs SDL2 via vcpkg on the Windows runner.
- Windows cmake_args now passes the vcpkg toolchain + x64-windows
  triplet.
- Verify step now asserts that sam3_image.exe and sam3_video.exe
  actually exist, so the silent-skip regression cannot return.

Verified locally on macOS: both GUI examples rebuild cleanly after the
SDL_opengl.h switch and the loader change.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@PABannier PABannier merged commit 909ae80 into main Apr 10, 2026
3 checks passed
@PABannier PABannier deleted the fix/windows-build-issue-5 branch April 10, 2026 08:40
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.

A Windows build of sam3.cpp

1 participant