gpt4 book ai didi

crash - DirectX 应用程序导致计算机崩溃

转载 作者:行者123 更新时间:2023-12-03 15:49:46 24 4
gpt4 key购买 nike

我编写了一个 DirectX11 应用程序,该应用程序在带有 GeForce GT 555m 显卡的 Alienware 笔记本电脑上运行,所以我知道计算机支持它。

我遇到了这个奇怪的事情,如果我的笔记本电脑没有插入电源,它会在没有任何警告的情况下关闭,但是如果它插入电源,应用程序运行良好。

我试图用其他 DirectX11 应用程序来复制它,包括 DirectX 附带的示例,但是我的应用程序是唯一一个这样做的,但我使用与示例非常相似的代码。我一定错过了什么,但我不知道是什么。

这是我设置 SwapChain 和 RenderTargetView 的代码

ZeroMemory(&swapChainDesc, sizeof(swapChainDesc));
swapChainDesc.BufferCount = 1;
swapChainDesc.BufferDesc.Width = width;
swapChainDesc.BufferDesc.Height = height;
swapChainDesc.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;

if(vsync) {
swapChainDesc.BufferDesc.RefreshRate.Numerator = numerator;
swapChainDesc.BufferDesc.RefreshRate.Denominator = denominator;
}
else {
swapChainDesc.BufferDesc.RefreshRate.Numerator = 0;
swapChainDesc.BufferDesc.RefreshRate.Denominator = 1;
}

swapChainDesc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
swapChainDesc.OutputWindow = hwnd;
swapChainDesc.SampleDesc.Count = 1;
swapChainDesc.SampleDesc.Quality = 0;

if(fullscreen) {
swapChainDesc.Windowed = false;
}
else {
swapChainDesc.Windowed = true;
}

swapChainDesc.BufferDesc.ScanlineOrdering = DXGI_MODE_SCANLINE_ORDER_UNSPECIFIED;
swapChainDesc.BufferDesc.Scaling = DXGI_MODE_SCALING_UNSPECIFIED;
swapChainDesc.SwapEffect = DXGI_SWAP_EFFECT_DISCARD;
swapChainDesc.Flags = 0;

D3D_FEATURE_LEVEL featureLevels[4] = { D3D_FEATURE_LEVEL_11_0, D3D_FEATURE_LEVEL_10_1, D3D_FEATURE_LEVEL_10_0, D3D_FEATURE_LEVEL_9_3, };
if (FAILED(D3D11CreateDeviceAndSwapChain(0, D3D_DRIVER_TYPE_HARDWARE, 0, 0, featureLevels, 4, D3D11_SDK_VERSION, &swapChainDesc, &swapChain, &device, &featureLevel, &deviceContext))) {
if (!device) {
printf("Insanity Error: Failed To Create Direct3D Device\n");
}
if (!swapChain) {
printf("Insanity Error: Failed To Create Swap Chain\n");
}
return false;
}
else {
switch (featureLevel) {
case D3D_FEATURE_LEVEL_11_0:
printf("Insanity Info: Currently Using DirectX 11.0\n");
break;
case D3D_FEATURE_LEVEL_10_1:
printf("Insanity Info: Currently Using DirectX 10.1\n");
break;
case D3D_FEATURE_LEVEL_10_0:
printf("Insanity Info: Currently Using DirectX 10.0\n");
break;
case D3D_FEATURE_LEVEL_9_3:
printf("Insanity Info: Currently Using DirectX 9.3\n");
break;
default:
printf("Insanity Info: Graphics System Unknown\n");
break;
}
}
if (FAILED(swapChain->GetBuffer(0, __uuidof(ID3D11Texture2D), (LPVOID*)&backBufferPtr))) {
printf("Insanity Error: Faield To Find Back Buffer\n");
return false;
}
if (FAILED(device->CreateRenderTargetView(backBufferPtr, 0, &renderTargetView))) {
printf("Insanity Error: Failed To Create Render View Target\n");
return false;
}
backBufferPtr->Release();
backBufferPtr = 0;

然后这是我设置 DepthStencilState 和 RasterState 的代码
    ZeroMemory(&depthStencilDesc, sizeof(D3D11_DEPTH_STENCIL_DESC));
depthStencilDesc.DepthEnable = false;
depthStencilDesc.DepthWriteMask = D3D11_DEPTH_WRITE_MASK_ALL;
depthStencilDesc.DepthFunc = D3D11_COMPARISON_LESS;
depthStencilDesc.StencilEnable = true;
depthStencilDesc.StencilReadMask = 0xFF;
depthStencilDesc.StencilWriteMask = 0xFF;
depthStencilDesc.FrontFace.StencilFailOp = D3D11_STENCIL_OP_KEEP;
depthStencilDesc.FrontFace.StencilDepthFailOp = D3D11_STENCIL_OP_INCR;
depthStencilDesc.FrontFace.StencilPassOp = D3D11_STENCIL_OP_KEEP;
depthStencilDesc.FrontFace.StencilFunc = D3D11_COMPARISON_ALWAYS;
depthStencilDesc.BackFace.StencilFailOp = D3D11_STENCIL_OP_KEEP;
depthStencilDesc.BackFace.StencilDepthFailOp = D3D11_STENCIL_OP_DECR;
depthStencilDesc.BackFace.StencilPassOp = D3D11_STENCIL_OP_KEEP;
depthStencilDesc.BackFace.StencilFunc = D3D11_COMPARISON_ALWAYS;
if (FAILED(device->CreateDepthStencilState(&depthStencilDesc, &depthDisableStencilState))) {
printf("Insanity Error: Failed To Create Depth State\n");
return false;
}

deviceContext->OMSetDepthStencilState(depthEnableStencilState, 1);
this->enableDepthTesting = true;

ZeroMemory(&depthStencilViewDesc, sizeof(depthStencilViewDesc));
depthStencilViewDesc.Format = depthBufferDesc.Format;
depthStencilViewDesc.ViewDimension = D3D11_DSV_DIMENSION_TEXTURE2D;
depthStencilViewDesc.Texture2D.MipSlice = 0;
if (FAILED(device->CreateDepthStencilView(depthStencilBuffer, &depthStencilViewDesc, &depthStencilView))) {
printf("Insanity Error: Failed To Create Depth View\n");
return false;
}

rasterDesc.AntialiasedLineEnable = false;
rasterDesc.CullMode = D3D11_CULL_NONE;
rasterDesc.DepthBias = 0;
rasterDesc.DepthBiasClamp = 0.0f;
rasterDesc.DepthClipEnable = true;
rasterDesc.FillMode = D3D11_FILL_SOLID;
rasterDesc.FrontCounterClockwise = false;
rasterDesc.MultisampleEnable = false;
rasterDesc.ScissorEnable = true;
rasterDesc.SlopeScaledDepthBias = 0.0f;

if (FAILED(device->CreateRasterizerState(&rasterDesc, &rasterState))) {
printf("Insanity Error: Failed To Create Rasterizer State\n");
return false;
}

deviceContext->RSSetState(rasterState);

如果有人对可能发生的事情有任何想法,请提供帮助!

最佳答案

尝试使用引用设备而不是硬件设备,看看问题是否再次出现。这应该有助于将驱动程序与代码隔离开来。创 build 备时,请改用 D3D_DRIVER_TYPE_REFERENCE .

关于crash - DirectX 应用程序导致计算机崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13358783/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com