{"record":{"id":"2b7f3990a029675a","repo":"stride3d/stride","slug":"cannot-create-a-texture-view-with-flags-viewflags-from-the","errorCode":null,"errorMessage":"Cannot create a Texture View with flags [{ViewFlags}] from the parent Texture with flags [{Flags}]. The parent Texture must include all the flags defined by the Texture View","messagePattern":"Cannot create a Texture View with flags \\[(.+?)\\] from the parent Texture with flags \\[(.+?)\\]\\. The parent Texture must include all the flags defined by the Texture View","errorType":"exception","errorClass":"NotSupportedException","httpStatus":null,"severity":"error","filePath":"sources/engine/Stride.Graphics/Texture.cs","lineNumber":520,"sourceCode":"\n            ViewWidth = Math.Max(1, Width >> MipLevel);\n            ViewHeight = Math.Max(1, Height >> MipLevel);\n            ViewDepth = Math.Max(1, Depth >> MipLevel);\n\n            if (ViewFormat == PixelFormat.None)\n            {\n                textureViewDescription.Format = deviceDescription.Format;\n            }\n            if (ViewFlags == TextureFlags.None)\n            {\n                textureViewDescription.Flags = deviceDescription.Flags;\n            }\n\n            // Check that the Texture View flags are compatible with the parent Texture's flags\n            var filterViewFlags = (TextureFlags)((int)ViewFlags & (~DepthStencilReadOnlyFlags));\n            if ((Flags & filterViewFlags) != filterViewFlags)\n            {\n                throw new NotSupportedException(\n                    $\"Cannot create a Texture View with flags [{ViewFlags}] from the parent Texture with flags [{Flags}]. \" +\n                    $\"The parent Texture must include all the flags defined by the Texture View\");\n            }\n\n            if (IsMultiSampled)\n            {\n                var maxCount = GraphicsDevice.Features[Format].MultisampleCountMax;\n                if (maxCount < MultisampleCount)\n                    throw new NotSupportedException(\n                        $\"Cannot create a Texture with format {Format} and multi-sample level {MultisampleCount}. \" +\n                        $\"The maximum supported level is {maxCount}\");\n            }\n\n            InitializeFromImpl(textureDatas);\n\n            return this;\n        }\n","sourceCodeStart":502,"sourceCodeEnd":538,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/engine/Stride.Graphics/Texture.cs#L502-L538","documentation":"When initializing a Texture View (a view onto a parent texture), Stride checks that the parent texture's Flags include every flag the view requires (after masking out DepthStencilReadOnlyFlags). NotSupportedException is thrown when the view requests flags (e.g. RenderTarget, ShaderResource, DepthStencil) the parent texture was not created with.","triggerScenarios":"Calling Texture.InitializeFrom with a TextureDescription whose ViewFlags exceed the parent texture's Flags — e.g. creating a render-target view over a ShaderResource-only texture, or a depth-stencil view over a color texture.","commonSituations":"Creating views for MRT or shadow-map sampling when the base texture lacks matching flags; refactors where the parent texture flags were narrowed; attempting cube-face views with mismatched flags.","solutions":["Recreate the parent texture with TextureFlags covering all ViewFlags (parent.Flags | ViewFlags).","Reduce the view's ViewFlags to a subset of the parent texture's flags.","Check DepthStencilReadOnlyFlags handling if the view is depth-stencil related."],"exampleFix":"// before\nvar parent = Texture.New2D(device, w, h, fmt, TextureFlags.ShaderResource);\nvar view = new Texture(parent.GraphicsDevice).InitializeFrom(parent, descWithViewFlags: TextureFlags.RenderTarget);\n// after\nvar parent = Texture.New2D(device, w, h, fmt, TextureFlags.ShaderResource | TextureFlags.RenderTarget);\nvar view = new Texture(parent.GraphicsDevice).InitializeFrom(parent, descWithViewFlags: TextureFlags.RenderTarget);","handlingStrategy":"validation","validationCode":"var filterViewFlags = (TextureFlags)((int)viewFlags & ~(int)TextureFlags.DepthStencilReadOnly);\nif ((parent.Flags & filterViewFlags) != filterViewFlags)\n    throw new InvalidOperationException($\"Parent flags {parent.Flags} do not include view flags {viewFlags}\");","typeGuard":"static bool CanCreateView(Texture parent, TextureFlags viewFlags) => (parent.Flags & viewFlags) == viewFlags;","tryCatchPattern":"try { view = new Texture(device).InitializeFrom(parent, desc); }\ncatch (NotSupportedException ex)\n{\n    logger.LogError(ex, \"View flags incompatible with parent flags {Flags}\", parent.Flags);\n    throw;\n}","preventionTips":["Create parent textures with the union of all flags any view will need.","Derive view flags from the parent's flags instead of hard-coding them.","Document required flags next to view-creation call sites."],"tags":["graphics","stride","texture-view","flags"],"backgroundTag":"unsupported-operation","analyzedSha":"96fad776d210c221682aac1ccdf4c79dc046fc38","analyzedAt":"2026-09-14T02:59:31.279Z","contentChangedAt":"2026-09-14T02:59:31.279Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}