Fixed crash when resizing window

This commit is contained in:
Simon Lübeß
2026-08-16 16:43:15 +02:00
parent fd2b990a8f
commit 229629a587
4 changed files with 20 additions and 3 deletions
+3
View File
@@ -426,6 +426,9 @@ namespace GlitchyEditor
// Clear the swapchain-buffer
RenderCommand.Clear(null, .Color | .Depth, .(0.2f, 0.2f, 0.2f), 1.0f, 0);
// Explicitly set the swap chain as render target, because we end a frame with it bound and the RTV might stop existing if we resized the swapchain between frames.
// TODO: maybe we need to be smarter about how we handle resizing in general: should the RenderTarget check during resize whether it is bound and update the GraphicsContext?!
RenderCommand.SetRenderTarget(null);
RenderCommand.SetBlendState(_alphaBlendState);
RenderCommand.SetDepthStencilState(_depthStencilState);
@@ -72,6 +72,8 @@ namespace GlitchyEngine.Renderer
{
PlatformCreateTexture();
}
SetDebugNames();
if(_description.DepthStencilFormat != .Unknown)
{
@@ -131,6 +133,18 @@ namespace GlitchyEngine.Renderer
}
}
private void SetDebugNames()
{
_nativeTexture.SetDebugName(Identifier);
_nativeResourceView.SetDebugName(scope $"{Identifier}: SRV");
_nativeRenderTargetView.SetDebugName(scope $"{Identifier}: RTV");
if (_depthStenilTarget != null)
{
_depthStenilTarget.nativeView.SetDebugName(scope $"{Identifier}: DSV");
}
}
protected override TextureViewBinding PlatformGetViewBinding()
{
return new .(_nativeResourceView, _samplerState?.nativeSamplerState);
@@ -255,6 +269,7 @@ namespace GlitchyEngine.Renderer
ID3D11Texture2D* texture = null;
var result = NativeDevice.CreateTexture2D(ref desc, null, &texture);
texture.SetDebugName(target.DebugName);
Log.EngineLogger.Assert(result.Succeeded, "Failed to create RenderTarget2D");
// TODO: calculate the max mip level
@@ -116,8 +116,9 @@ namespace GlitchyEngine.Renderer
desc.IsSwapchainTarget = true;
_backBuffer = new RenderTarget2D(desc);
_backBuffer.Identifier = "Backbuffer";
_backBuffer.Identifier = "Back buffer";
_backBuffer.SamplerState = SamplerStateManager.LinearClamp;
_backBuffer.ApplyChanges();
}
_backBufferViewport = GlitchyEngine.Renderer.Viewport(0, 0, _width, _height, 0.0f, 1.0f);
@@ -62,8 +62,6 @@ namespace GlitchyEngine.Renderer
Debug.Profiler.ProfileResourceFunction!();
_description = description;
ApplyChanges();
}
/// Recreates the render target using the current description