Files
kinect/docs/linux-wine.md
T
kinect-botandsisyphus-dev-ai c08bc922b6 feat(tracker): add Linux cursor calibration, matching the Windows flow exactly
"the cursor scaling is still wrong, make it like the windows one" - the
Linux tracker had no way to calibrate at all. The in-game cursor's arm-reach
gains (default 3.2/2.6) were tuned specifically for the native Windows
tracker's camera/pose characteristics via its "Calibrate cursor" button
(core/calibration.h's derive_arm_gains); Linux users were stuck on that
default regardless of their own camera/body, with no equivalent tool.

tracker/calibration.py is a byte-for-byte port of core/calibration.h's
arm-gain derivation (mean(|reach|) -> target/mean, clamped [1,6]) and the
calibration.cfg text format load_config()/save_config() share, so a config
written by either side is read identically by the shim - not a
reimplementation that happens to produce similar numbers, the same formula
and the same wire format, verified against tests/test_calibration.cpp's own
cases (averaging, diagonal-gesture success, horizontal-only rejection,
clamp-to-min, save/reload round-trip) ported 1:1 into
tests/test_calibration_py.py - 6/6 passing, plus the existing tracker suite
still 11/11.

tracker.py gets a --calibrate mode (calibrate_cursor()): mirrors each frame
for pose inference exactly like the main loop, computes Kinect joints with
mirror=False, and reads HAND_LEFT (index 7) minus SHOULDER_LEFT (index 4) -
the slots the player's actual right arm lands in post-mirror, pre-shim-swap,
matching exactly where win_main.cpp's CalibrateCursor() reads
skeleton.joints[7]/[4] (verified by reading that function directly). Usage:
nix run .#tracker -- --calibrate --source 0.

docs/calibration.md and docs/linux-wine.md document the Linux flow, the
Linux default config path (no %LOCALAPPDATA% equivalent - XDG config dir),
and that KINECT_SHIM_CONFIG must be set explicitly in both the calibration
tool's environment and the game's launch options (Wine or Proton) so they
agree on one file - the same pattern already established for
KINECT_SHIM_SHM_FILE.

Co-authored-by: sisyphus-dev-ai <sisyphus-dev-ai@users.noreply.github.com>
2026-11-30 12:53:45 -05:00

6.2 KiB

Running DEA + the tracker entirely on Linux, under Wine

This is a third path beyond the two in the README: DEA and the Kinect10.dll shim run under Wine on Linux, but the tracker runs as a native Linux process, outside Wine.

Why not just run kinect-tracker.exe under Wine too

tracker-native/ captures the webcam through Windows Media Foundation (MFEnumDeviceSources + IMFSourceReader). Wine's mf.dll has video-capture device enumeration as a hard stub (confirmed directly in Wine's source, dlls/mf/main.c::MFEnumDeviceSources):

if (IsEqualGUID(&source_type, &MF_DEVSOURCE_ATTRIBUTE_SOURCE_TYPE_VIDCAP_GUID))
{
    FIXME("Not implemented for video capture devices.\n");
    *ret_count = 0;
    return S_OK;
}

It always reports zero devices - no camera ever shows up, and kinect-tracker.exe null-derefs downstream of that empty list (the Unhandled page fault ... address 00006FFFFE9A8C34 crash you get running it under Wine is this). This isn't fixable from our side; it's a gap in Wine's Media Foundation implementation.

The fix: bridge the already-verified Linux tracker through a real file

The shim's shared-memory region is normally an anonymous, Wine-private pagefile section (CreateFileMappingW(INVALID_HANDLE_VALUE, ...)), invisible outside that one Wine instance. The Python tracker (tracker/), which already has full native webcam access (verified Linux path, docs/setup-linux.md), publishes through multiprocessing.shared_memory, which on Linux is backed by a real file at /dev/shm/<name>.

The shim now supports opening that real file directly as a file-backed mapping (KINECT_SHIM_SHM_FILE env var, fallback/windows-nui/src/frame_source.cpp::open_file) instead of the named anonymous section. Since Wine's default Z: drive maps the whole host filesystem, /dev/shm/virtual_kinect_frames on Linux is Z:\dev\shm\virtual_kinect_frames from inside Wine - so the Wine-hosted shim and the native-Linux tracker end up mapping the exact same tmpfs file. No Wine camera support needed at all.

 webcam --(V4L2)--> tracker/ (Python, native Linux process)
                        |  writes multiprocessing.shared_memory "virtual_kinect_frames"
                        v
          /dev/shm/virtual_kinect_frames   (a real file, same on both sides)
                        ^
                        |  CreateFileW + file-backed CreateFileMappingW
         Kinect10.dll shim (inside Wine, inside the DEA process) --> game

Steps

  1. Build the shim (already done in this repo as of this change; rebuild if you pull newer source):

    ./fallback/windows-nui/build.sh
    

    Copy fallback/windows-nui/build/Kinect10-x86.dll (or -x64, matching DEA's bitness) into the DEA contents folder next to gamekdm.dll, as Kinect10.dll - same as docs/setup-windows.md step 2.

  2. Set up the Linux tracker environment per docs/setup-linux.md steps 0-2 (with Nix, nix develop does this in one shot - no venv, no manual libGLESv2.so.2 staging; without Nix, the uv/Python 3.12 venv path). You do not need the OpenNI2 steps (3-5) for this path - those are for the separate Linux/OpenNI2 target, not DEA.

  3. Confirm your Wine Z: drive maps to / (the default):

    ls -la ~/.wine/dosdevices/z:      # expect a symlink to /
    

    If it's remapped or you use a non-default WINEPREFIX, adjust the path in step 5 accordingly (or add your own Z:-equivalent drive mapping to /dev/shm).

  4. Run the Linux tracker, pointing it at a shm name you'll reuse below:

    # with Nix:
    nix run .#tracker -- --source 0 --depth-size 640x480 --shm-name virtual_kinect_frames
    
    # without Nix:
    export LD_LIBRARY_PATH="$HOME/.cache/kinect/gllibs:$LD_LIBRARY_PATH"   # if needed
    tracker/.venv/bin/python -m tracker.tracker --source 0 \
      --depth-size 640x480 --shm-name virtual_kinect_frames
    

    This creates /dev/shm/virtual_kinect_frames and keeps publishing live frames into it.

  5. Launch DEA with KINECT_SHIM_SHM_FILE set, pointing at that same file through the Z: drive. Plain Wine:

    WINEPREFIX=/path/to/your/prefix \
    KINECT_SHIM_SHM_FILE='Z:\dev\shm\virtual_kinect_frames' \
    wine spice2x.exe   # (or however you normally launch it)
    

    Steam Proton (add spice2x/DEA as a non-Steam game, force a Proton version in Properties -> Compatibility): put the same assignment in Properties -> General -> Launch Options, prefixed before %command%:

    KINECT_SHIM_SHM_FILE='Z:\dev\shm\virtual_kinect_frames' %command%
    

    The shim reads KINECT_SHIM_SHM_FILE once at NuiInitialize and, when set, opens that path as a file-backed mapping instead of looking for the named Wine section. Check kinect_shim.log for a shm-file='...' open=1 line to confirm it attached.

  6. Calibrate the cursor - required on Linux, there is no built-in default that fits every camera. With the tracker set up, run:

    nix run .#tracker -- --calibrate --source 0
    

    and raise your right arm as prompted. Then set KINECT_SHIM_CONFIG the same way as KINECT_SHIM_SHM_FILE above (same Z:-drive path translation) in the launch options, so the shim reads the gains this just wrote. See docs/calibration.md for the full guide and the exact env var to set. Everything downstream works the same as the Windows path - the shim doesn't care whether the bytes came from a Windows tracker or this Linux one, only that the contract layout matches (it's #pragma pack(1) and already cross-checked against the Python struct by the core test suite).

If it still doesn't attach

  • kinect_shim.log shows shm-file='...' open=0 (err=2): file not found - the tracker isn't running yet, the --shm-name doesn't match the path in KINECT_SHIM_SHM_FILE, or your Z: drive doesn't map where you think. Run winepath -w /dev/shm/virtual_kinect_frames from inside the prefix to get the exact Windows-side path Wine expects.
  • The shim attaches but the game shows no skeleton: this is the same validity/tracking pipeline as the Windows path - see docs/troubleshooting.md and docs/game-internals.md. Nothing about the file-backed bridge changes that logic; it's purely a transport swap.