{"record":{"id":"97abc402d52a1786","repo":"stride3d/stride","slug":"cannot-swap-texture-views-only-root-textures-can-be-swapped","errorCode":null,"errorMessage":"Cannot swap texture views; only root textures can be swapped.","messagePattern":"Cannot swap texture views; only root textures can be swapped\\.","errorType":"exception","errorClass":"NotSupportedException","httpStatus":null,"severity":"error","filePath":"sources/engine/Stride.Graphics/Texture.cs","lineNumber":1822,"sourceCode":"            ArgumentNullException.ThrowIfNull(textureData);\n\n            // Check that the textureData has the correct size for the Texture's data\n            Image.ComputePitch(format, width, height, out var rowPitch, out var slicePitch, out _, out _);\n\n            if (sizeof(TData) * textureData.Length != (slicePitch * depth))\n                throw new ArgumentException(\"Invalid Texture data length\", nameof(textureData));\n\n            return new DataBox(fixedPointer, rowPitch, slicePitch);\n        }\n\n        /// <summary>\n        ///   Swaps the Texture's internal data with another Texture.\n        /// </summary>\n        /// <param name=\"other\">The other Texture.</param>\n        internal void Swap([NotNull] Texture other)\n        {\n            if (ParentTexture is not null || other.ParentTexture is not null)\n                throw new NotSupportedException(\"Cannot swap texture views; only root textures can be swapped.\");\n\n            (textureDescription, other.textureDescription) = (other.textureDescription, textureDescription);\n            (textureViewDescription, other.textureViewDescription) = (other.textureViewDescription, textureViewDescription);\n            (mipmapDescriptions, other.mipmapDescriptions) = (other.mipmapDescriptions, mipmapDescriptions);\n            (fullQualitySize, other.fullQualitySize) = (other.fullQualitySize, fullQualitySize);\n\n            (other.ViewWidth, ViewWidth) = (ViewWidth, other.ViewWidth);\n            (other.ViewHeight, ViewHeight) = (ViewHeight, other.ViewHeight);\n            (other.ViewDepth, ViewDepth) = (ViewDepth, other.ViewDepth);\n            (other.SizeInBytes, SizeInBytes) = (SizeInBytes, other.SizeInBytes);\n\n            SwapInternal(other);\n        }\n\n        /// <summary>\n        ///   Computes the bounds of a Texture View based on the View type, which determines what sub-Resources\n        ///   the Texture View can access.\n        /// </summary>","sourceCodeStart":1804,"sourceCodeEnd":1840,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/engine/Stride.Graphics/Texture.cs#L1804-L1840","documentation":"Thrown by the internal Texture.Swap method when either texture is a view (has a ParentTexture). Swapping only exchanges root-level descriptions and view descriptions, so swapping views is unsupported and would corrupt state. Raised as NotSupportedException.","triggerScenarios":"Calling Texture.Swap(other) where this.ParentTexture or other.ParentTexture is non-null, i.e. either texture was created as a view (e.g. via CreateView / slice / mip view) of another texture.","commonSituations":"Engine-level code that swaps render targets hitting a view (e.g. a cube-face or array-slice view); pooling textures where a pooled item was registered as a view.","solutions":["Swap only root textures; obtain the root via the texture's ParentTexture chain and swap those.","Skip the swap when ParentTexture is not null, or recreate independent textures instead of views.","If you need view-like behavior, swap the underlying root textures and recreate views afterwards."],"exampleFix":"// before\ntextureView.Swap(otherView); // both are views\n// after\nvar rootA = textureView.ParentTexture ?? textureView;\nvar rootB = otherView.ParentTexture ?? otherView;\nrootA.Swap(rootB);","handlingStrategy":"type-guard","validationCode":"if (texture.ParentTexture is not null || other.ParentTexture is not null)\n    throw new InvalidOperationException(\"Swap requires root textures\");","typeGuard":"bool IsRootTexture(Texture t) => t is not null && t.ParentTexture is null;","tryCatchPattern":null,"preventionTips":["Track which pooled textures are views.","Resolve to the root texture (walk ParentTexture) before swapping.","This is an internal API — avoid swapping views by design."],"tags":["graphics","unsupported-operation","texture-view"],"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"}