SubtitleEdit/subtitleedit · error · InvalidOperationException
Failed to create software render context: {GetErrorString(er
Error message
Failed to create software render context: {GetErrorString(err)} What it means
InvalidOperationException: mpv_render_context_create returned a negative code for the MPV_RENDER_API_TYPE_SW parameters. The mpv core initialized successfully but could not create a software render context.
Source
Thrown at src/ui/Logic/VideoPlayers/LibMpvDynamic/LibMpvDynamicPlayer.cs:1821
new MpvRenderParam { type = MPV_RENDER_PARAM_INVALID, data = IntPtr.Zero }
};
var renderParamsSize = Marshal.SizeOf<MpvRenderParam>() * renderParams.Length;
var renderParamsPtr = Marshal.AllocHGlobal(renderParamsSize);
try
{
for (var i = 0; i < renderParams.Length; i++)
{
var offset = renderParamsPtr + (i * Marshal.SizeOf<MpvRenderParam>());
Marshal.StructureToPtr(renderParams[i], offset, false);
}
// Create render context
err = _mpvRenderContextCreate(out _renderContext, _mpv, renderParamsPtr);
if (err < 0)
{
throw new InvalidOperationException($"Failed to create software render context: {GetErrorString(err)}");
}
// Set update callback
_renderUpdateCallback = OnRenderUpdate;
var callbackPtr = Marshal.GetFunctionPointerForDelegate(_renderUpdateCallback);
_mpvRenderContextSetUpdateCallback(_renderContext, callbackPtr, IntPtr.Zero);
}
finally
{
Marshal.FreeHGlobal(renderParamsPtr);
}
}
finally
{
Marshal.FreeHGlobal(apiTypePtr);
}
}
View on GitHub (pinned to 17a9f07487)
Solutions
- Use a libmpv build that supports software rendering.
- Fall back to a GPU vo render context when software context creation fails.
- Verify the MpvRenderParam marshalling matches the linked libmpv's ABI.
Example fix
// before
err = _mpvRenderContextCreate(out _renderContext, _mpv, renderParamsPtr);
if (err < 0) throw new InvalidOperationException($"Failed to create software render context: {GetErrorString(err)}");
// after
err = _mpvRenderContextCreate(out _renderContext, _mpv, renderParamsPtr);
if (err < 0)
{
logger.LogWarning("software render context unavailable: {Msg}", GetErrorString(err));
await SwitchToGpuVoAsync();
} Defensive patterns
Strategy: try-catch
Validate before calling
if (!LibMpvSupportsSoftwareRender())
{
logger.LogWarning("libmpv has no SW render; using GPU vo");
SwitchToGpuVo();
return;
} Try / catch
try { player.InitializeWithSoftwareRendering(); }
catch (InvalidOperationException ex) when (ex.Message.Contains("software render context"))
{
logger.LogWarning("{Msg}; falling back to GPU vo", ex.Message);
await SwitchToGpuVoAsync();
} Prevention
- Bundle a full libmpv build that supports software rendering.
- Offer a GPU-vo fallback when SW context creation fails.
- Verify the MpvRenderParam marshalling matches the linked ABI.
When it happens
Trigger: A libmpv build compiled without software-render support, an SW render API type unsupported by the loaded build, a GPU-only libmpv, or an MpvRenderParam struct layout mismatch across ABI versions.
Common situations: Minimal or embedded libmpv builds, or a version skew where the marshalled MpvRenderParam layout no longer matches the linked library.
Related errors
- MPV delegates not loaded for software rendering.
- Failed to initialize mpv: {_mpvContext.GetErrorString(err)}
- Failed to initialize mpv: {_mpvContext.GetErrorString(err)}
- Failed to initialize mpv: {player.GetErrorString(err)}
- Failed to initialize mpv: {_mpvPlayer.GetErrorString(err)}
AI-assisted analysis of SubtitleEdit/subtitleedit@17a9f07487 (2026-08-13).
Data as JSON: /api/errors/2f7fea35f96330fb.
Report an issue: GitHub.