3

*** FML: IT WAS FRAPS. Stopped the DX screen recording software and it works. Special thanks to @zdd for doing some joint testing which helped me figure this out. ***

Remeber: FRAPS + D3D11_CREATE_DEVICE_DEBUG + SampleDesc.Count > 1 don't mix.

I'm really new to DX... as in a week old. But the problem is very easy to describe, even with my limited lingo and understanding. I'm keeping the DEBUG layer on as it provides valuable feedback. But in turn it creates a problem I can't overcome. I've spent 1 day pulling hairs strand by strand.

THE PROBLEM

If I create a D3D11 device with:

vSwapChainDesc.SampleDesc.Count = 4;
vSwapChainDesc.SampleDesc.Quality = 3;

... it crashes on the final ->Release(), no matter which object it is. The exact same DAMN code with:

vSwapChainDesc.SampleDesc.Count = 1;
vSwapChainDesc.SampleDesc.Quality = 0;

... cleans up COM references smoothly. Not to mention that both variants work fine in Release without DEBUG flag.

In the Output, I get some cryptic error saying live children without parents. But I have only 5 COM objects I use with a COM wrapper.

So I removed the COM wrapper, doing the ->Release() and = nullptr by hand for each of them. It is IMPOSSIBLE to be releasing something by mistake, IMO. And on the final ->Release() it says it hit a breakpoint.

So... has anyone else encountered such behavior? I don't think I can get an answer unless someone else went through the exact same thing. It's so weird...

The Code

// Uncomment this and it all works... like magic!
// #undef _DEBUG

#pragma region Includes
#include <stdio.h>
#include <conio.h>
#include <map>
#include <windows.h>
#include <d3d11.h>

#pragma comment (lib, "dxgi.lib")
#pragma comment (lib, "d3d11.lib")
#pragma endregion

#pragma region Com Helpers
// track the refcounts on ->Release() :)
std::map<std::string, int> g_ComCounter;

template <typename Interface_t>
Interface_t** ComRelease(Interface_t** aPointer, LPCSTR aName) {
    if(!aPointer) {
        DebugBreak();
    }

    if(*aPointer) {
        // save refcount for debug
        g_ComCounter[aName] = (*aPointer)->Release();
        *aPointer = nullptr;
    }
    printf("Destroyed %p (%s:%d).\r\n", *aPointer, aName, g_ComCounter[aName]);

    return aPointer;
}

#define COM_RELEASE(Pointer) ComRelease(&Pointer, #Pointer)

template <typename Interface_t>
Interface_t** ComPointer(Interface_t** aPointer, LPCSTR aName) {
    if(!aPointer) {
        DebugBreak();
    }

    if(*aPointer) {
        // save refcount for debug
        g_ComCounter[aName] = (*aPointer)->Release();
        *aPointer = nullptr;
    }
    printf("Prepared %p (%s:%d).\r\n", *aPointer, aName, g_ComCounter[aName]);

    // Object is being Acquired

    return aPointer;
}

#define COM_POINTER(Pointer) ComPointer(&Pointer, #Pointer)
#pragma endregion

#pragma region Window Proc
LRESULT CALLBACK WndProc(HWND hWnd, UINT uMessage, WPARAM wParam, LPARAM lParam) {
    PAINTSTRUCT vPainStruct = { 0 };
    HDC vDc(nullptr);

    switch(uMessage) {
        case WM_PAINT:
            vDc = BeginPaint(hWnd, &vPainStruct);
            EndPaint(hWnd, &vPainStruct);
            return FALSE;
            break;
        case WM_ERASEBKGND:
            // Don't erase background!
            return TRUE;
            break;
        case WM_CLOSE:
            DestroyWindow(hWnd);
            break;
        case WM_DESTROY:
            PostQuitMessage(0);
            break;
        default:
            break;
    }

    return DefWindowProc(hWnd, uMessage, wParam, lParam);
}
#pragma endregion

#ifdef _CONSOLE
int wmain(int aArgc, const WCHAR* aArgv[]) {
#else
int wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PWSTR pCmdLine, int nCmdShow) {
#endif
#pragma region Variables
    HINSTANCE                   vInstance = GetModuleHandle(nullptr);
    HWND                        vHwnd = nullptr;
    D3D_DRIVER_TYPE             vDriverType = D3D_DRIVER_TYPE_UNKNOWN;
    D3D_FEATURE_LEVEL           vFeatureLevel = D3D_FEATURE_LEVEL_11_0;
    IDXGIFactory                *vDxgiFactory = nullptr;
    IDXGIAdapter                *vDxgiAdapter = nullptr;
    ID3D11Device                *vD3dDevice = nullptr;
    ID3D11DeviceContext         *vD3dContext = nullptr;
    IDXGISwapChain              *vSwapChain = nullptr;
    ID3D11Texture2D             *vBackBuffer(nullptr);
    ID3D11RenderTargetView      *vRenderTargetView = nullptr;
#ifdef _DEBUG
    ID3D11Debug                 *vDebugger = nullptr;
    ID3D11InfoQueue             *vInfoQueue = nullptr;
#endif
#pragma endregion

#pragma region Init Window
    // Register class
    WNDCLASSEX vWndClass;
    ZeroMemory(&vWndClass, sizeof(vWndClass));
    vWndClass.cbSize = sizeof(WNDCLASSEX);
    vWndClass.style = 0; // CS_HREDRAW | CS_VREDRAW (draw in loop, no need for WM_PAINT)
    vWndClass.lpfnWndProc = WndProc;
    vWndClass.cbClsExtra = 0;
    vWndClass.cbWndExtra = 0;
    vWndClass.hInstance = vInstance;
    vWndClass.hIcon = 0;
    vWndClass.hCursor = LoadCursor(nullptr, IDC_ARROW);
    vWndClass.hbrBackground = nullptr;
    vWndClass.lpszMenuName = nullptr;
    vWndClass.lpszClassName = L"D3d11Window";
    vWndClass.hIconSm = 0;
    if(!RegisterClassEx(&vWndClass)) {
        DebugBreak();
        return 0;
    }

    // Create window
    RECT vWindowRect = { 0, 0, 640, 480 };
    AdjustWindowRect(&vWindowRect, WS_OVERLAPPEDWINDOW, FALSE);
    vHwnd = CreateWindowEx(
        0, vWndClass.lpszClassName, L"D3D11", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
        CW_USEDEFAULT, CW_USEDEFAULT,
        vWindowRect.right - vWindowRect.left, vWindowRect.bottom - vWindowRect.top,
        nullptr, nullptr, vInstance,
        nullptr);
    if(!vHwnd) {
        DebugBreak();
        return 0;
    }

    ShowWindow(vHwnd, SW_SHOWDEFAULT);
#pragma endregion

#pragma region Initialization
    RECT vClientRect = { 0 };
    GetClientRect(vHwnd, &vClientRect);
    UINT vWidth = vClientRect.right - vClientRect.left;
    UINT vHeight = vClientRect.bottom - vClientRect.top;

    if(FAILED(CreateDXGIFactory(__uuidof(IDXGIFactory), (void**)COM_POINTER(vDxgiFactory)))) {
        DebugBreak();
        return 0;
    }

    if(FAILED(vDxgiFactory->EnumAdapters(0, COM_POINTER(vDxgiAdapter)))) {
        DebugBreak();
        return 0;
    }

    D3D_FEATURE_LEVEL vRequestedFeatureLevels[] = {
        D3D_FEATURE_LEVEL_11_0,
        // D3D_FEATURE_LEVEL_10_1,
        // D3D_FEATURE_LEVEL_10_0
    };

    UINT vNumFeatureLevels = ARRAYSIZE(vRequestedFeatureLevels);

    UINT vDeviceFlags = 0;
#ifdef _DEBUG
    vDeviceFlags |= D3D11_CREATE_DEVICE_DEBUG;
#endif

    if(FAILED(D3D11CreateDevice(
        vDxgiAdapter,
        vDriverType,
        nullptr,
        vDeviceFlags,
        vRequestedFeatureLevels,
        vNumFeatureLevels,
        D3D11_SDK_VERSION,
        COM_POINTER(vD3dDevice),
        &vFeatureLevel,
        COM_POINTER(vD3dContext)))) {
        return 0;
    }

#ifdef _DEBUG
    if(FAILED(vD3dDevice->QueryInterface(__uuidof(ID3D11Debug), (LPVOID*)COM_POINTER(vDebugger)))) {
        return 0;
    }
    if(FAILED(vDebugger->QueryInterface(__uuidof(ID3D11InfoQueue), (LPVOID*)COM_POINTER(vInfoQueue)))) {
        return 0;
    }
    vInfoQueue->SetBreakOnSeverity(D3D11_MESSAGE_SEVERITY_CORRUPTION, true);
    vInfoQueue->SetBreakOnSeverity(D3D11_MESSAGE_SEVERITY_ERROR, true);
    vDebugger->ReportLiveDeviceObjects(D3D11_RLDO_SUMMARY | D3D11_RLDO_DETAIL);
#endif

    UINT vMsaaQuality = 0;
    if(FAILED(vD3dDevice->CheckMultisampleQualityLevels(DXGI_FORMAT_R8G8B8A8_UNORM, 4, &vMsaaQuality)) || (vMsaaQuality < 1)) {
        return 0;
    }
    printf("MsaaQuality: %d for 4\r\n", vMsaaQuality);

    DXGI_SWAP_CHAIN_DESC vSwapChainDesc;
    ZeroMemory(&vSwapChainDesc, sizeof(vSwapChainDesc));
    vSwapChainDesc.BufferCount = 2;
    vSwapChainDesc.BufferDesc.Width = vWidth;
    vSwapChainDesc.BufferDesc.Height = vHeight;
    vSwapChainDesc.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
    vSwapChainDesc.BufferDesc.RefreshRate.Numerator = 60;
    vSwapChainDesc.BufferDesc.RefreshRate.Denominator = 1;
    vSwapChainDesc.BufferDesc.ScanlineOrdering = DXGI_MODE_SCANLINE_ORDER_UNSPECIFIED;
    vSwapChainDesc.BufferDesc.Scaling = DXGI_MODE_SCALING_CENTERED;
    vSwapChainDesc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
    vSwapChainDesc.SampleDesc.Count = 4; // set 1 for the code to work              vSwapChainDesc.SampleDesc.Quality = vMsaaQuality - 1;
    vSwapChainDesc.OutputWindow = vHwnd;
    vSwapChainDesc.Windowed = true;
    vSwapChainDesc.SwapEffect = DXGI_SWAP_EFFECT_DISCARD;
    vSwapChainDesc.Flags = DXGI_SWAP_CHAIN_FLAG_ALLOW_MODE_SWITCH;

    if(FAILED(vDxgiFactory->CreateSwapChain(vD3dDevice, &vSwapChainDesc, COM_POINTER(vSwapChain)))) {
        return 0;
    }

    if(FAILED(vSwapChain->GetBuffer(0, __uuidof(ID3D11Texture2D), (LPVOID*)COM_POINTER(vBackBuffer)))) {
        return 0;
    }

    if(FAILED(vD3dDevice->CreateRenderTargetView(vBackBuffer, nullptr, COM_POINTER(vRenderTargetView)))) {
        return 0;
    }

    vD3dContext->OMSetRenderTargets(1, &vRenderTargetView, nullptr);

    D3D11_VIEWPORT vViewport = { 0 };
    vViewport.Width = static_cast<FLOAT>(vWidth);
    vViewport.Height = static_cast<FLOAT>(vHeight);
    vViewport.MinDepth = D3D11_MIN_DEPTH;
    vViewport.MaxDepth = D3D11_MAX_DEPTH;
    vViewport.TopLeftX = 0;
    vViewport.TopLeftY = 0;
    vD3dContext->RSSetViewports(1, &vViewport);
#pragma endregion

#pragma region Game Loop
    MSG vMessage = { 0 };
    while(WM_QUIT != vMessage.message) {
        while(PeekMessage(&vMessage, 0, 0, 0, PM_REMOVE)) {
            TranslateMessage(&vMessage);
            DispatchMessage(&vMessage);
        }

        if(WM_QUIT == vMessage.message) {
            break;
        }

#pragma region Render
        float vClearColor[4] = { 0.0f, 0.0f, 0.0f, 1.0f };
        vD3dContext->ClearRenderTargetView(vRenderTargetView, vClearColor);
        vSwapChain->Present(true, 0); // vsync
#pragma endregion
    }
#pragma endregion

#pragma region Cleanup
    if(vSwapChain) {
        vSwapChain->SetFullscreenState(false, nullptr);
    }
    if(vD3dContext) {
        vD3dContext->ClearState();
    }

    COM_RELEASE(vRenderTargetView);
    COM_RELEASE(vBackBuffer);
    COM_RELEASE(vSwapChain);
    COM_RELEASE(vD3dContext);
    COM_RELEASE(vD3dDevice);
    COM_RELEASE(vDxgiFactory);
    COM_RELEASE(vDxgiAdapter);

#ifdef _DEBUG
    COM_RELEASE(vDebugger);
    COM_RELEASE(vInfoQueue);
#endif

    printf("\r\nREF COUNTS AFTER RELEASE():\r\n");
    for(const auto& vComCount : g_ComCounter) {
        printf("%s:%d\r\n", vComCount.first.c_str(), vComCount.second);
    }

#pragma endregion

    _getch();
    return (int)vMessage.wParam;
}

HELP!

If you want me to comment the code to better explain the logic, I will. I get comments mentioning things that are clearly explain the question and code... Maybe I'm not clear enough.

Final Thoughts

Maybe there's some kind of release function internal to certain objects I'm not calling. Maybe I'm doing something out of order or really wrong. But I got this from a reputable website. And it matches the Hello DirectX! code in the books I'm currently indulging myself with.

This snippet is stripped down and minimalistic. It's a trimmed version of a more complex one while trying to identify the problem. Plus I removed all OOP to have it in one block of code easy to follow.

Now there's a final question: Is there another way to smooth lines except this SampleDesc one?

PS: It's Windows 7 x64, VS 2013 + 2014 CTP. And the card supports it as it works (edges are smooth) in both debug and release mode. It's only the final release that fails in debug mode.

CodeAngry
  • 12,760
  • 3
  • 50
  • 57
  • don't write your own [com_ptr](http://msdn.microsoft.com/en-us/library/417w8b3b.aspx) library... there are many good ones from Microsoft that will save you from pain. – Mgetz Mar 08 '14 at 13:42
  • @Mgetz My COM works properly *(tested for a long time on `MSHTML`, `MSXML`, `D2D`, `WIC` and such)* plus it's move enabled. **But this example has any COM wrapper stripped away completely.** I'm working with the raw COM pointers. The code has no dependencies outside the SDK *(so no code from my own library)*. – CodeAngry Mar 08 '14 at 13:52

2 Answers2

1

I don't know why your code crashes, but I would like to share some of my experiences of DirectX programming based on your code, :)

  1. Use win32 app instead of console app
  2. The ComRelease function was too compixity, you don't need so much code, just one line is enough.
  3. Don't wrap d3d pointers to ComPointer.

A more clean code as below, you will get rid of the complexity COM stuff and focus on the code logic to check the crash.

#define DEBUG
#pragma region Includes
#include <stdio.h>
#include <conio.h>
#include <windows.h>
#include <d3d11.h>

#pragma comment (lib, "dxgi.lib")
#pragma comment (lib, "d3d11.lib")
#pragma endregion

// Release COM object
#define SAFE_RELEASE(P) if(P){ P->Release(); P = NULL;}

#pragma region Window Proc
LRESULT CALLBACK WndProc(HWND hWnd, UINT uMessage, WPARAM wParam, LPARAM lParam) {
    PAINTSTRUCT vPainStruct = { 0 };
    HDC vDc(nullptr);

    switch(uMessage) {
        case WM_PAINT:
            vDc = BeginPaint(hWnd, &vPainStruct);
            EndPaint(hWnd, &vPainStruct);
            return FALSE;
            break;
        case WM_ERASEBKGND:
            // Don't erase background!
            return TRUE;
            break;
        case WM_CLOSE:
            DestroyWindow(hWnd);
            break;
        case WM_DESTROY:
            PostQuitMessage(0);
            break;
        default:
            break;
    }

    return DefWindowProc(hWnd, uMessage, wParam, lParam);
}
#pragma endregion

int main() {
#pragma region Variables
    HINSTANCE                   vInstance = GetModuleHandle(nullptr);
    HWND                        vHwnd = nullptr;
    D3D_DRIVER_TYPE             vDriverType = D3D_DRIVER_TYPE_UNKNOWN;
    D3D_FEATURE_LEVEL           vFeatureLevel = D3D_FEATURE_LEVEL_11_0;
    IDXGIFactory                *vDxgiFactory = NULL;
    IDXGIAdapter                *vDxgiAdapter = nullptr;
    ID3D11Device                *vD3dDevice = nullptr;
    ID3D11DeviceContext         *vD3dContext = nullptr;
    IDXGISwapChain              *vSwapChain = nullptr;
    ID3D11Texture2D             *vBackBuffer = NULL;
    ID3D11RenderTargetView      *vRenderTargetView = nullptr;
#ifdef _DEBUG
    ID3D11Debug                 *vDebugger = nullptr;
    ID3D11InfoQueue             *vInfoQueue = nullptr;
#endif
#pragma endregion

#pragma region Init Window
    // Register class
    WNDCLASSEX vWndClass;
    ZeroMemory(&vWndClass, sizeof(vWndClass));
    vWndClass.cbSize = sizeof(WNDCLASSEX);
    vWndClass.style = 0; // CS_HREDRAW | CS_VREDRAW (draw in loop, no need for WM_PAINT)
    vWndClass.lpfnWndProc = WndProc;
    vWndClass.cbClsExtra = 0;
    vWndClass.cbWndExtra = 0;
    vWndClass.hInstance = vInstance;
    vWndClass.hIcon = 0;
    vWndClass.hCursor = LoadCursor(nullptr, IDC_ARROW);
    vWndClass.hbrBackground = nullptr;
    vWndClass.lpszMenuName = nullptr;
    vWndClass.lpszClassName = L"D3d11Window";
    vWndClass.hIconSm = 0;
    if(!RegisterClassEx(&vWndClass)) {
        DebugBreak();
        return 0;
    }

    // Create window
    RECT vWindowRect = { 0, 0, 640, 480 };
    vHwnd = CreateWindowEx(
        0, vWndClass.lpszClassName, L"D3D11", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
        CW_USEDEFAULT, CW_USEDEFAULT,
        vWindowRect.right - vWindowRect.left, vWindowRect.bottom - vWindowRect.top,
        nullptr, nullptr, vInstance,
        nullptr);
    if(!vHwnd) {
        DebugBreak();
        return 0;
    }

    ShowWindow(vHwnd, SW_SHOWDEFAULT);
#pragma endregion

#pragma region Initialization
    RECT vClientRect = { 0 };
    GetClientRect(vHwnd, &vClientRect);
    UINT vWidth = vClientRect.right - vClientRect.left;
    UINT vHeight = vClientRect.bottom - vClientRect.top;

    if(FAILED(CreateDXGIFactory(__uuidof(IDXGIFactory), (void**)(&vDxgiFactory)))) {
        DebugBreak();
        return 0;
    }

    if(FAILED(vDxgiFactory->EnumAdapters(0, &vDxgiAdapter))) {
        DebugBreak();
        return 0;
    }

    D3D_FEATURE_LEVEL vRequestedFeatureLevels[] = {
        D3D_FEATURE_LEVEL_11_0,
        // D3D_FEATURE_LEVEL_10_1,
        // D3D_FEATURE_LEVEL_10_0
    };

    UINT vNumFeatureLevels = ARRAYSIZE(vRequestedFeatureLevels);

    UINT vDeviceFlags = 0;
#ifdef _DEBUG
    vDeviceFlags |= D3D11_CREATE_DEVICE_DEBUG;
#endif

    if(FAILED(D3D11CreateDevice(
        vDxgiAdapter,
        vDriverType,
        nullptr,
        vDeviceFlags,
        vRequestedFeatureLevels,
        vNumFeatureLevels,
        D3D11_SDK_VERSION,
        &vD3dDevice,
        &vFeatureLevel,
        &vD3dContext))) {
        return 0;
    }

    UINT vMsaaQuality = 0;
    if(FAILED(vD3dDevice->CheckMultisampleQualityLevels(DXGI_FORMAT_R8G8B8A8_UNORM, 4, &vMsaaQuality)) || (vMsaaQuality < 1)) {
        return 0;
    }
    printf("MsaaQuality of max %d supported for count 4\r\n", vMsaaQuality);

    DXGI_SWAP_CHAIN_DESC vSwapChainDesc;
    ZeroMemory(&vSwapChainDesc, sizeof(vSwapChainDesc));
    vSwapChainDesc.BufferCount = 2;
    vSwapChainDesc.BufferDesc.Width = vWidth;
    vSwapChainDesc.BufferDesc.Height = vHeight;
    vSwapChainDesc.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
    vSwapChainDesc.BufferDesc.RefreshRate.Numerator = 60;
    vSwapChainDesc.BufferDesc.RefreshRate.Denominator = 1;
    vSwapChainDesc.BufferDesc.ScanlineOrdering = DXGI_MODE_SCANLINE_ORDER_UNSPECIFIED;
    vSwapChainDesc.BufferDesc.Scaling = DXGI_MODE_SCALING_CENTERED;
    vSwapChainDesc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
    vSwapChainDesc.SampleDesc.Count = 4; // set 1 to work
    vSwapChainDesc.SampleDesc.Quality = vMsaaQuality - 1;
    vSwapChainDesc.OutputWindow = vHwnd;
    vSwapChainDesc.Windowed = true;
    vSwapChainDesc.SwapEffect = DXGI_SWAP_EFFECT_DISCARD;
    vSwapChainDesc.Flags = DXGI_SWAP_CHAIN_FLAG_ALLOW_MODE_SWITCH;

    if(FAILED(vDxgiFactory->CreateSwapChain(vD3dDevice, &vSwapChainDesc, &vSwapChain))) {
        return 0;
    }

    if(FAILED(vSwapChain->GetBuffer(0, __uuidof(ID3D11Texture2D), (LPVOID*)&vBackBuffer))) {
        return 0;
    }

    if(FAILED(vD3dDevice->CreateRenderTargetView(vBackBuffer, nullptr, &vRenderTargetView))) {
        return 0;
    }

    vD3dContext->OMSetRenderTargets(1, &vRenderTargetView, nullptr);

    D3D11_VIEWPORT vViewport = { 0 };
    vViewport.Width = static_cast<FLOAT>(vWidth);
    vViewport.Height = static_cast<FLOAT>(vHeight);
    vViewport.MinDepth = D3D11_MIN_DEPTH;
    vViewport.MaxDepth = D3D11_MAX_DEPTH;
    vViewport.TopLeftX = 0;
    vViewport.TopLeftY = 0;
    vD3dContext->RSSetViewports(1, &vViewport);
#pragma endregion

#pragma region Game Loop
    MSG vMessage = { 0 };
    while(WM_QUIT != vMessage.message) {
        while(PeekMessage(&vMessage, 0, 0, 0, PM_REMOVE)) {
            TranslateMessage(&vMessage);
            DispatchMessage(&vMessage);
        }

        if(WM_QUIT == vMessage.message) {
            break;
        }

#pragma region Render
        float vClearColor[4] = { 1.0f, 0.0f, 0.0f, 1.0f };
        vD3dContext->ClearRenderTargetView(vRenderTargetView, vClearColor);
        vSwapChain->Present(true, 0); // vsync
#pragma endregion
    }
#pragma endregion

#pragma region Cleanup
    if(vSwapChain) {
        vSwapChain->SetFullscreenState(false, nullptr);
    }
    if(vD3dContext) {
        vD3dContext->ClearState();
    }

    SAFE_RELEASE(vRenderTargetView);
    SAFE_RELEASE(vBackBuffer);
    SAFE_RELEASE(vSwapChain);
    SAFE_RELEASE(vD3dContext);
    SAFE_RELEASE(vD3dDevice);
    SAFE_RELEASE(vDxgiFactory);
    SAFE_RELEASE(vDxgiAdapter);

#ifdef _DEBUG
    SAFE_RELEASE(vDebugger);
    SAFE_RELEASE(vInfoQueue);
#endif


#pragma endregion

    _getch();
    return (int)vMessage.wParam;
}
CodeAngry
  • 12,760
  • 3
  • 50
  • 57
zdd
  • 8,258
  • 8
  • 46
  • 75
  • :) I did all that crazy wrapping to track objects properly, intentionally. As it was saying `live child without parent`, I wanted to actually count the references myself and double check it. The code is the minimal code required to reproduce it. And that COM madness is especially written for this post, so anyone can see everything gets freed properly so they don't look for problems there... **Also switched to a Windows application to no avail.** I use the console for easy debugging output. When running the application, the console window moves to my second display and prints helpful stuff. – CodeAngry Mar 08 '14 at 14:28
  • @CodeAngry to trace debugging output, you should use the output window in Visual Studio, you can get everything there. there are lots of information when debugging mode was turn on. – zdd Mar 09 '14 at 00:27
  • @melak47 I think he refers to what I'm doing in this code snippet where I'm not just thin wrapping then but also counting rafs with a map. – CodeAngry Mar 09 '14 at 00:27
  • @zdd I know exactly what the problem is. It says, when I release the last object COM object, that I have `a live child without parent`. That means a parent is fully released while a child holds a reference. Which is impossible... if you look in the code. That's why all the COM wrapping, to show anyone answering that what `Output` window is saying is impossible. I'm freeing everything properly. – CodeAngry Mar 09 '14 at 00:29
  • @CodeAngry the code I post works fine without any error or warnings. So i think it was caused by your COM wrappers. – zdd Mar 09 '14 at 00:37
  • @zdd Please seek this line of code: `vSwapChainDesc.SampleDesc.Count = 1; // set 4 or 8 to crash`. I posted functional code in the snippet, assuming those who try it will change it to break it. That's stupid! I should have posted broken code and comment how to fix it. Edited question. PS: It's not working, for me anyways... `vSwapChainDesc.SampleDesc.Count = 4;` use this value and please let me know if it exists clean. If it does, it might just be me. – CodeAngry Mar 09 '14 at 01:03
  • Set SampleDesc.Count = 4; and SampleDesc.Quality = 0; this works fine, but SampleDesc.Count = 4; and SampleDesc.Quality = 3; does not work, it seems my card does not support this, what i got in the output window is: D3D11 ERROR: ID3D11Device::CreateTexture2D: SampleDesc.Quality specifies invalid value 3. For 4 samples, the current graphics implementation only supports SampleDesc.Quality less than 1. <-- if 0 is shown here for Quality, this means the graphics implementation doesn't support 4 samples at all. Use CheckMultisampleQualityLevels to detect what the graphics implementation supports – zdd Mar 09 '14 at 01:13
  • @zdd Made a change to your posted code. Please try this one. It will output the max msaa `quality` supported for a `count = 4`. And it will set `max - 1` as `Quality`. For me it still crashes on exist with 0 for quality and 4 for count. – CodeAngry Mar 09 '14 at 01:26
  • @CodeAngry the max msaa I got is 1, so count = 4 and quality = 1 also works for me. – zdd Mar 09 '14 at 01:30
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/49333/discussion-between-zdd-and-codeangry) – zdd Mar 09 '14 at 01:31
0

Check if your card support Quality=3 with CheckMultisampleQualityLevels. If it's just for lines I'd suggest try alpha anti aliasing D3D11_RASTERIZER_DESC.AntialiasedLineEnable

  • *Does that rasterizer affect all geometries or just literarily lines?* PS: **The card supports it.** I test with `->CheckMultisampleQualityLevels()`. And as I said, it works in both debug & release mode. It makes shapes smooth, just that it crashes on exit *(final release)*. – CodeAngry Mar 08 '14 at 13:36
  • can you paste the code to check the quality levels? – zdd Mar 08 '14 at 14:05