Skip to content

Fix/fix example3 macos display crash#138

Open
HapiJimDream wants to merge 2 commits intoVector-Wangel:mainfrom
HapiJimDream:fix/fix-example3-macos-display-crash
Open

Fix/fix example3 macos display crash#138
HapiJimDream wants to merge 2 commits intoVector-Wangel:mainfrom
HapiJimDream:fix/fix-example3-macos-display-crash

Conversation

@HapiJimDream
Copy link
Copy Markdown

Problem

On macOS, running 3_so100_yolo_ee_control.py crashes with:

NSWindow should only be instantiated on the main thread!

Root Cause:

  • macOS AppKit framework strictly requires NSWindow (used by OpenCV's cv2.imshow()) to be created and managed on the main thread only
  • The original implementation ran YOLO inference + video display in a daemon sub-thread, violating macOS UI thread safety rules
  • Linux/Windows don't have this restriction, so the issue was macOS-specific

Solution

Implemented a producer-consumer pattern with thread separation:

Component Thread Responsibility
YOLO Inference Sub-thread (background) Read camera → Run model inference → Put result in queue
Video Display Main thread (UI) Get frame from queue → cv2.imshow()
Robot Control Main thread (UI) Keyboard input → P control → Send actions

Key Changes (For MacOS )

  • Sub-thread handles heavy computation (YOLO inference ~100ms)
  • Main thread only does lightweight tasks (display + control ~5ms)
  • Queue-based communication

Testing

  • ✅ macOS: Video window displays correctly, no NSWindow exception
  • ✅ Keyboard control responds smoothly
  • ✅ YOLO detection overlay visible in real-time
  • ✅ Compatible with Linux/Windows

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