stride3d/stride · error · ArgumentNullException
adapter
Error message
adapter
What it means
The GraphicsOutput constructor requires a non-null GraphicsAdapter and throws ArgumentNullException("adapter") when passed null. This guards internal enumeration: each display output must be attached to the adapter that owns it. Callers (typically GraphicsAdapterFactory enumeration code) are expected to always supply a valid adapter.
Solutions
- Ensure GraphicsAdapterFactory.Current/adapter enumeration succeeded before constructing GraphicsOutput.
- Pass a valid GraphicsAdapter instance obtained from GraphicsAdapterFactory.Adapters.
- If no adapter exists, fail earlier with a clear 'no graphics adapter' error instead of constructing outputs.
Example fix
// before var output = new GraphicsOutput(null, displayProperties, 0); // after var adapter = GraphicsAdapterFactory.Adapters[0]; var output = new GraphicsOutput(adapter, displayProperties, 0);
Defensive patterns
Strategy: type-guard
Validate before calling
if (adapter == null) throw new ArgumentNullException(nameof(adapter)); // caller-side check before constructing GraphicsOutput
Type guard
bool IsValidOutputArgs(GraphicsAdapter a) => a is not null;
Try / catch
try { var output = new GraphicsOutput(adapter, displayProps, i); }
catch (ArgumentNullException ex) { log.Error("Adapter was null during output enumeration", ex); } Prevention
- Resolve adapters via GraphicsAdapterFactory before building outputs
- Fail fast with a clear message when adapter enumeration returns empty
- Never pass nullable adapter values into graphics factory plumbing without checks
When it happens
Trigger: Constructing GraphicsOutput directly (internal constructor) with a null adapter argument, e.g. custom factory/plumbing code that passes null instead of a GraphicsAdapter instance.
Common situations: Custom graphics factory or initialization code that fails to resolve an adapter (adapter enumeration returned null) and passes it straight into GraphicsOutput; refactoring where adapter lookup was removed but the call site kept.
Related errors
- ArgumentNullException: removeAction
- ArgumentNullException: session
- ArgumentNullException: templates
- compilerParameters
- graphicsDevice
AI-assisted analysis of stride3d/stride@96fad776d2 (2026-09-14).
Data as JSON: /api/errors/3d6e1cc7ef0b193c.
Report an issue: GitHub.
Appendix: source
Thrown at sources/engine/Stride.Graphics/Vulkan/GraphicsOutput.Vulkan.cs:36
/// <unmanaged-short>IDXGIOutput</unmanaged-short>
public partial class GraphicsOutput
{
private readonly VkDisplayPropertiesKHR displayProperties;
private readonly int outputIndex;
// TODO VULKAN
internal GraphicsOutput() { } // Here for GraphicsAdapter.Vulkan to be able to create a GraphicsOutput without an adapter
/// <summary>
/// Initializes a new instance of <see cref="GraphicsOutput" />.
/// </summary>
/// <param name="adapter">The adapter.</param>
/// <param name="outputIndex">Index of the output.</param>
/// <exception cref="System.ArgumentNullException">output</exception>
/// <exception cref="ArgumentOutOfRangeException">output</exception>
internal GraphicsOutput(GraphicsAdapter adapter, VkDisplayPropertiesKHR displayProperties, int outputIndex)
{
if (adapter == null) throw new ArgumentNullException("adapter");
this.outputIndex = outputIndex;
this.displayProperties = displayProperties;
DesktopBounds = new Rectangle(0, 0, (int)displayProperties.physicalResolution.width, (int)displayProperties.physicalResolution.height);
}
/// <summary>
/// Find the display mode that most closely matches the requested display mode.
/// </summary>
/// <param name="targetProfiles">The target profile, as available formats are different depending on the feature level..</param>
/// <param name="mode">The mode.</param>
/// <returns>Returns the closes display mode.</returns>
/// <unmanaged>HRESULT IDXGIOutput::FindClosestMatchingMode([In] const DXGI_MODE_DESC* pModeToMatch,[Out] DXGI_MODE_DESC* pClosestMatch,[In, Optional] IUnknown* pConcernedDevice)</unmanaged>
/// <remarks>Direct3D devices require UNORM formats. This method finds the closest matching available display mode to the mode specified in pModeToMatch. Similarly ranked fields (i.e. all specified, or all unspecified, etc) are resolved in the following order. ScanlineOrdering Scaling Format Resolution RefreshRate When determining the closest value for a particular field, previously matched fields are used to filter the display mode list choices, and other fields are ignored. For example, when matching Resolution, the display mode list will have already been filtered by a certain ScanlineOrdering, Scaling, and Format, while RefreshRate is ignored. This ordering doesn't define the absolute ordering for every usage scenario of FindClosestMatchingMode, because the application can choose some values initially, effectively changing the order that fields are chosen. Fields of the display mode are matched one at a time, generally in a specified order. If a field is unspecified, FindClosestMatchingMode gravitates toward the values for the desktop related to this output. If this output is not part of the desktop, then the default desktop output is used to find values. If an application uses a fully unspecified display mode, FindClosestMatchingMode will typically return a display mode that matches the desktop settings for this output. Unspecified fields are lower priority than specified fields and will be resolved later than specified fields.</remarks>
public DisplayMode FindClosestMatchingDisplayMode(ReadOnlySpan<GraphicsProfile> targetProfiles, DisplayMode mode)
{
View on GitHub (pinned to 96fad776d2)