{"record":{"id":"d1dfe11836f46b84","repo":"SubtitleEdit/subtitleedit","slug":"mpv-delegates-not-loaded-for-software-rendering","errorCode":null,"errorMessage":"MPV delegates not loaded for software rendering.","messagePattern":"MPV delegates not loaded for software rendering\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/ui/Logic/VideoPlayers/LibMpvDynamic/LibMpvDynamicPlayer.cs","lineNumber":1779,"sourceCode":"        var err = DoMpvCommand(\"set\", \"aid\", trackId.ToString(CultureInfo.InvariantCulture));\n        if (err < 0)\n        {\n            Se.LogError(new InvalidOperationException(GetErrorString(err)), \"LibMpvDynamicPlayer SetAudioTrack\");\n        }\n    }\n\n    public void InitializeWithSoftwareRendering()\n    {\n        LoadLibraryInternal();\n        EnsureNotDisposed();\n\n        // Set mpv to use software rendering\n        SetOptionString(\"vo\", \"libmpv\");\n        SetStartPausedOption();\n\n        if (_mpvInitialize == null || _mpvRenderContextCreate == null || _mpvRenderContextSetUpdateCallback == null)\n        {\n            throw new InvalidOperationException(\"MPV delegates not loaded for software rendering.\");\n        }\n\n        SetYtDlpPathOption();\n\n        // Initialize mpv\n        var err = _mpvInitialize(_mpv);\n        if (err < 0)\n        {\n            throw new InvalidOperationException(GetErrorString(err));\n        }\n\n        _coreInitialized = true;\n\n        // Build render context params for software rendering\n        var apiTypeBytes = Encoding.UTF8.GetBytes(MPV_RENDER_API_TYPE_SW + \"\\0\");\n        var apiTypePtr = Marshal.AllocHGlobal(apiTypeBytes.Length);\n        Marshal.Copy(apiTypeBytes, 0, apiTypePtr, apiTypeBytes.Length);\n","sourceCodeStart":1761,"sourceCodeEnd":1797,"githubUrl":"https://github.com/SubtitleEdit/subtitleedit/blob/17a9f0748781032255db3526b7215d2fb891e3af/src/ui/Logic/VideoPlayers/LibMpvDynamic/LibMpvDynamicPlayer.cs#L1761-L1797","documentation":"InvalidOperationException: after LoadLibraryInternal, at least one critical P/Invoke delegate (_mpvInitialize, _mpvRenderContextCreate, or _mpvRenderContextSetUpdateCallback) is still null. The native library loaded, but the expected symbols were not found, indicating an ABI/version mismatch.","triggerScenarios":"A libmpv is present but too old to export mpv_render_context_create/set_update_callback, the wrong library revision was loaded (e.g. libmpv.so.1 vs libmpv.so.2), a stripped/minimal build lacking the render API, or symbols renamed across versions.","commonSituations":"A distro libmpv older than required, multiple libmpv versions on the library path, or a custom minimal build compiled without the render context API.","solutions":["Install a libmpv build recent enough to export mpv_render_context_create and mpv_render_context_set_update_callback.","Ensure the loader resolves the bundled libmpv rather than a stale system copy (check rpath / LD_LIBRARY_PATH / dyld).","Fall back to a GPU vo context if software rendering is unavailable on this build."],"exampleFix":"// before\nif (_mpvInitialize == null || _mpvRenderContextCreate == null || _mpvRenderContextSetUpdateCallback == null)\n    throw new InvalidOperationException(\"MPV delegates not loaded for software rendering.\");\n\n// after\nif (_mpvInitialize == null || _mpvRenderContextCreate == null || _mpvRenderContextSetUpdateCallback == null)\n{\n    logger.LogWarning(\"libmpv lacks software-render API; falling back to GPU vo\");\n    SwitchToGpuVo();\n    return;\n}","handlingStrategy":"validation","validationCode":"if (!LibMpvExportsSymbol(\"mpv_render_context_create\"))\n{\n    logger.LogWarning(\"libmpv lacks render API; using GPU vo\");\n    SwitchToGpuVo();\n    return;\n}","typeGuard":null,"tryCatchPattern":"try { player.InitializeWithSoftwareRendering(); }\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"delegates not loaded\"))\n{\n    logger.LogWarning(\"{Msg}; falling back to GPU vo\", ex.Message);\n    SwitchToGpuVo();\n}","preventionTips":["Bundle a libmpv build that exports mpv_render_context_*.","Ensure the loader resolves the bundled library, not a stale system copy.","Version-gate the software-rendering feature.","Provide a GPU-vo fallback."],"tags":["mpv","native","abi","version","dllimport"],"backgroundTag":null,"analyzedSha":"17a9f0748781032255db3526b7215d2fb891e3af","analyzedAt":"2026-08-13T18:11:43.374Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}