Thanks to visit codestin.com
Credit goes to github.com

Skip to content

ComPtr<T> Detaching #1155

@RealityProgrammer

Description

@RealityProgrammer

Summary of feature

The API of ComPtr from wrl has Detach method, which will return the underlying handle to the object and nullify the handle inside the pointer. But for some reason, Silk.NET doesn't implement such method, which can be very helpful for cleaning interfaces in case error occur.

Example:

public ID3D12Device* Device;

static bool Initialize() {
    using ComPtr<ID3D12Device> pDevice = new();
    HResult hr = D3D12.CreateDevice(null, D3DFeatureLevel.Feature110, SilkMarshal.GuidPtrOf<ID3D12Device>(), (void**)pDevice.GetAddressOf());

    if (hr.IsFailure) {
        return false;
    }

    // Initialize ID3D12CommandQueue, IDXGIFactory, etc... here without having to release every successfully created object on every failure

    Device = pDevice.Detach();
}

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions