{"record":{"id":"9bae0c130593fa26","repo":"deepfakes/faceswap","slug":"an-unhandled-exception-occurred-reading-from-the-n","errorCode":null,"errorMessage":"An unhandled exception occurred reading from the Nvidia Machine Learning Library. Original error: {str(err)}","messagePattern":"An unhandled exception occurred reading from the Nvidia Machine Learning Library\\. Original error: (.+?)","errorType":"exception","errorClass":"FaceswapError","httpStatus":null,"severity":"error","filePath":"lib/gpu_stats/nvidia.py","lineNumber":59,"sourceCode":"            If the NVML library could not be successfully loaded\n        \"\"\"\n        if self._is_initialized:\n            return\n        try:\n            self._log(\"debug\", \"Initializing PyNVML for Nvidia GPU.\")\n            pynvml.nvmlInit()\n        except (pynvml.NVMLError_LibraryNotFound,  # pylint:disable=no-member\n                pynvml.NVMLError_DriverNotLoaded,  # pylint:disable=no-member\n                pynvml.NVMLError_NoPermission) as err:  # pylint:disable=no-member\n            msg = (\"There was an error reading from the Nvidia Machine Learning Library. The most \"\n                   \"likely cause is incorrectly installed drivers. If this is the case, Please \"\n                   \"remove and reinstall your Nvidia drivers before reporting. Original \"\n                   f\"Error: {str(err)}\")\n            raise FaceswapError(msg) from err\n        except Exception as err:  # pylint:disable=broad-except\n            msg = (\"An unhandled exception occurred reading from the Nvidia Machine Learning \"\n                   f\"Library. Original error: {str(err)}\")\n            raise FaceswapError(msg) from err\n\n        os.environ[\"CUDA_DEVICE_ORDER\"] = \"PCI_BUS_ID\"\n        super()._initialize()\n\n    def _shutdown(self) -> None:\n        \"\"\"Cleanly close access to NVML and set :attr:`_is_initialized` back to ``False``. \"\"\"\n        self._log(\"debug\", \"Shutting down NVML\")\n        pynvml.nvmlShutdown()\n        super()._shutdown()\n\n    def _get_device_count(self) -> int:\n        \"\"\"Detect the number of GPUs attached to the system.\n\n        Returns\n        -------\n        The total number of GPUs connected to the PC\n        \"\"\"\n        try:","sourceCodeStart":41,"sourceCodeEnd":77,"githubUrl":"https://github.com/deepfakes/faceswap/blob/f530cb7508ae670f6474f8a7d9c4df94705cf96b/lib/gpu_stats/nvidia.py#L41-L77","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["If calling the API directly, clamp the smaller dimension to >= 16 and round both to even: (max(16, min(d)), and d - d % 2)","Fix the scaling/theme setting that produced the tiny size (raise the scaling factor, correct user interface scaling in settings)","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"],"exampleFix":"# before\nbuild_arrow_image((11, 22), thickness=1, direction=\"left\")  # min side < 16 -> FaceswapError\n\n# after\nw, h = 11, 22\nw += w % 2\nh += h % 2\nif min(w, h) < 16:\n    scale = 16 / min(w, h)\n    w, h = int(w * scale) // 2 * 2, int(h * scale) // 2 * 2\nbuild_arrow_image((w, h), thickness=1, direction=\"left\")","handlingStrategy":"validation","validationCode":"def normalize_arrow_dims(w, h):\n    w += w % 2\n    h += h % 2\n    if min(w, h) < 16:\n        raise ValueError(\"arrow bitmap too small; increase scale\")\n    return w, h","typeGuard":"def valid_arrow_dimensions(dims) -> bool:\n    \"\"\"True when dims satisfy theme.py's arrow builder: both even, min side >= 16.\"\"\"\n    w, h = dims\n    return min(w, h) >= 16 and w % 2 == 0 and h % 2 == 0","tryCatchPattern":"from lib.utils import FaceswapError\ntry:\n    bitmap = build_arrow(dims, thickness, direction)\nexcept FaceswapError as err:\n    if \"arrow image\" in str(err):\n        bitmap = build_arrow(normalize_arrow_dims(*dims), thickness, direction)\n    else:\n        raise","preventionTips":["Clamp theme bitmap sizes to >=16px and even numbers","Validate scaling-derived sizes before rendering theme assets","Report/track the doc-vs-code mismatch (message says 8, code checks 16) upstream"],"tags":["faceswap","gui","theme","scaling","validation"],"backgroundTag":null,"analyzedSha":"f530cb7508ae670f6474f8a7d9c4df94705cf96b","analyzedAt":"2026-08-15T02:59:26.626Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}