{"record":{"id":"909afb61b2cf51ca","repo":"SubtitleEdit/subtitleedit","slug":"geterrorstring-err","errorCode":null,"errorMessage":"GetErrorString(err)","messagePattern":"GetErrorString\\(err\\)","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"critical","filePath":"src/ui/Logic/VideoPlayers/LibMpvDynamic/LibMpvDynamicPlayer.cs","lineNumber":1788,"sourceCode":"        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\n        try\n        {\n            var renderParams = new[]\n            {\n                new MpvRenderParam { type = MPV_RENDER_PARAM_API_TYPE, data = apiTypePtr },\n                new MpvRenderParam { type = MPV_RENDER_PARAM_INVALID, data = IntPtr.Zero }\n            };\n\n            var renderParamsSize = Marshal.SizeOf<MpvRenderParam>() * renderParams.Length;","sourceCodeStart":1770,"sourceCodeEnd":1806,"githubUrl":"https://github.com/SubtitleEdit/subtitleedit/blob/17a9f0748781032255db3526b7215d2fb891e3af/src/ui/Logic/VideoPlayers/LibMpvDynamic/LibMpvDynamicPlayer.cs#L1770-L1806","documentation":"InvalidOperationException whose message is mpv's own error string: _mpvInitialize(_mpv) returned a negative code during the software-rendering init path (after the required delegates were verified present). Same core-init failure class as the native control, reached via InitializeWithSoftwareRendering.","triggerScenarios":"mpv core cannot initialize during software rendering: missing codecs/drivers, conflicting option values, or display/server problems. Reached only after the delegate-presence check in 416 passes.","commonSituations":"A machine falling back to software rendering whose mpv core still cannot initialize (no decoders, broken option overrides), or a libmpv whose core init needs resources unavailable headless.","solutions":["Read the mpv error string in the message to pinpoint the failure.","Install libmpv dependencies and platform codecs.","Reset any mpv option overrides that may conflict with core init.","If even software init fails, disable the mpv video feature and offer an alternate player."],"exampleFix":"// before\nvar err = _mpvInitialize(_mpv);\nif (err < 0) throw new InvalidOperationException(GetErrorString(err));\n\n// after\nvar err = _mpvInitialize(_mpv);\nif (err < 0)\n{\n    logger.LogError(\"mpv core init failed: {Msg}\", GetErrorString(err));\n    DisableVideoFeature();\n    throw new InvalidOperationException(GetErrorString(err));\n}","handlingStrategy":"try-catch","validationCode":"if (!IsLibMpvAvailable()) { DisableVideoFeature(); return; }","typeGuard":null,"tryCatchPattern":"try { player.InitializeWithSoftwareRendering(); }\ncatch (InvalidOperationException ex)\n{\n    logger.LogError(\"mpv core init failed: {Msg}\", ex.Message);\n    DisableVideoFeature();\n}","preventionTips":["Ensure libmpv dependencies and codecs are installed.","Reset mpv option overrides before init.","Disable the video feature if even software init fails.","Log the mpv error string for diagnostics."],"tags":["mpv","video","native","initialization"],"backgroundTag":null,"analyzedSha":"17a9f0748781032255db3526b7215d2fb891e3af","analyzedAt":"2026-08-13T18:11:43.374Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}