deepfakes/faceswap · error · FaceswapError

An unhandled exception occurred reading from the Nvidia Mach

Error message

An unhandled exception occurred reading from the Nvidia Machine Learning Library. Original error: {str(err)}

What it means

lib/gui/theme.py builds the GUI's scaled arrow bitmaps (e.g. combo/slider decorations) as numpy arrays. It computes square_size = min(height, width) and requires square_size >= 16 (despite the message text saying 8) and both dimensions even; otherwise FaceswapError.

Source

Thrown at lib/gpu_stats/nvidia.py:59

            If the NVML library could not be successfully loaded
        """
        if self._is_initialized:
            return
        try:
            self._log("debug", "Initializing PyNVML for Nvidia GPU.")
            pynvml.nvmlInit()
        except (pynvml.NVMLError_LibraryNotFound,  # pylint:disable=no-member
                pynvml.NVMLError_DriverNotLoaded,  # pylint:disable=no-member
                pynvml.NVMLError_NoPermission) as err:  # pylint:disable=no-member
            msg = ("There was an error reading from the Nvidia Machine Learning Library. The most "
                   "likely cause is incorrectly installed drivers. If this is the case, Please "
                   "remove and reinstall your Nvidia drivers before reporting. Original "
                   f"Error: {str(err)}")
            raise FaceswapError(msg) from err
        except Exception as err:  # pylint:disable=broad-except
            msg = ("An unhandled exception occurred reading from the Nvidia Machine Learning "
                   f"Library. Original error: {str(err)}")
            raise FaceswapError(msg) from err

        os.environ["CUDA_DEVICE_ORDER"] = "PCI_BUS_ID"
        super()._initialize()

    def _shutdown(self) -> None:
        """Cleanly close access to NVML and set :attr:`_is_initialized` back to ``False``. """
        self._log("debug", "Shutting down NVML")
        pynvml.nvmlShutdown()
        super()._shutdown()

    def _get_device_count(self) -> int:
        """Detect the number of GPUs attached to the system.

        Returns
        -------
        The total number of GPUs connected to the PC
        """
        try:

View on GitHub (pinned to f530cb7508)

Solutions

  1. If calling the API directly, clamp the smaller dimension to >= 16 and round both to even: (max(16, min(d)), and d - d % 2)
  2. Fix the scaling/theme setting that produced the tiny size (raise the scaling factor, correct user interface scaling in settings)
  3. Update Faceswap — the message/limit mismatch ('8' vs code's 16) indicates this area has been revised; a newer build may accept smaller sizes or validate earlier

Example fix

# before
build_arrow_image((11, 22), thickness=1, direction="left")  # min side < 16 -> FaceswapError

# after
w, h = 11, 22
w += w % 2
h += h % 2
if min(w, h) < 16:
    scale = 16 / min(w, h)
    w, h = int(w * scale) // 2 * 2, int(h * scale) // 2 * 2
build_arrow_image((w, h), thickness=1, direction="left")
Defensive patterns

Strategy: validation

Validate before calling

def normalize_arrow_dims(w, h):
    w += w % 2
    h += h % 2
    if min(w, h) < 16:
        raise ValueError("arrow bitmap too small; increase scale")
    return w, h

Type guard

def valid_arrow_dimensions(dims) -> bool:
    """True when dims satisfy theme.py's arrow builder: both even, min side >= 16."""
    w, h = dims
    return min(w, h) >= 16 and w % 2 == 0 and h % 2 == 0

Try / catch

from lib.utils import FaceswapError
try:
    bitmap = build_arrow(dims, thickness, direction)
except FaceswapError as err:
    if "arrow image" in str(err):
        bitmap = build_arrow(normalize_arrow_dims(*dims), thickness, direction)
    else:
        raise

Prevention

When it happens

Trigger: Calling the arrow-image builder (via GUI theme setup) with dimensions where the smaller side is under 16px or either dimension is odd — e.g. an extremely small scaling factor or a user/theme scaling config producing tiny/odd widget sizes. Triggered during GUI startup/theme refresh, not by normal CLI use.

Common situations: Very high display scaling compressing a bitmap request below 16px; custom themes with non-standard widget metrics; DPI/scale settings yielding odd pixel sizes; code that calls the builder directly with hand-computed sizes.

Related errors


AI-assisted analysis of deepfakes/faceswap@f530cb7508 (2026-08-15). Data as JSON: /api/errors/9bae0c130593fa26. Report an issue: GitHub.