SubtitleEdit/subtitleedit · critical · InvalidOperationException

GetErrorString(err)

Error message

GetErrorString(err)

What it means

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.

Source

Thrown at src/ui/Logic/VideoPlayers/LibMpvDynamic/LibMpvDynamicPlayer.cs:1788

        LoadLibraryInternal();
        EnsureNotDisposed();

        // Set mpv to use software rendering
        SetOptionString("vo", "libmpv");
        SetStartPausedOption();

        if (_mpvInitialize == null || _mpvRenderContextCreate == null || _mpvRenderContextSetUpdateCallback == null)
        {
            throw new InvalidOperationException("MPV delegates not loaded for software rendering.");
        }

        SetYtDlpPathOption();

        // Initialize mpv
        var err = _mpvInitialize(_mpv);
        if (err < 0)
        {
            throw new InvalidOperationException(GetErrorString(err));
        }

        _coreInitialized = true;

        // Build render context params for software rendering
        var apiTypeBytes = Encoding.UTF8.GetBytes(MPV_RENDER_API_TYPE_SW + "\0");
        var apiTypePtr = Marshal.AllocHGlobal(apiTypeBytes.Length);
        Marshal.Copy(apiTypeBytes, 0, apiTypePtr, apiTypeBytes.Length);

        try
        {
            var renderParams = new[]
            {
                new MpvRenderParam { type = MPV_RENDER_PARAM_API_TYPE, data = apiTypePtr },
                new MpvRenderParam { type = MPV_RENDER_PARAM_INVALID, data = IntPtr.Zero }
            };

            var renderParamsSize = Marshal.SizeOf<MpvRenderParam>() * renderParams.Length;

View on GitHub (pinned to 17a9f07487)

Solutions

  1. Read the mpv error string in the message to pinpoint the failure.
  2. Install libmpv dependencies and platform codecs.
  3. Reset any mpv option overrides that may conflict with core init.
  4. If even software init fails, disable the mpv video feature and offer an alternate player.

Example fix

// before
var err = _mpvInitialize(_mpv);
if (err < 0) throw new InvalidOperationException(GetErrorString(err));

// after
var err = _mpvInitialize(_mpv);
if (err < 0)
{
    logger.LogError("mpv core init failed: {Msg}", GetErrorString(err));
    DisableVideoFeature();
    throw new InvalidOperationException(GetErrorString(err));
}
Defensive patterns

Strategy: try-catch

Validate before calling

if (!IsLibMpvAvailable()) { DisableVideoFeature(); return; }

Try / catch

try { player.InitializeWithSoftwareRendering(); }
catch (InvalidOperationException ex)
{
    logger.LogError("mpv core init failed: {Msg}", ex.Message);
    DisableVideoFeature();
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of SubtitleEdit/subtitleedit@17a9f07487 (2026-08-13). Data as JSON: /api/errors/909afb61b2cf51ca. Report an issue: GitHub.