Skip to content

ComPtr<T> Detaching #1155

Closed
Closed
@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

    pFad - Phonifier reborn

    Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

    Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


    Alternative Proxies:

    Alternative Proxy

    pFad Proxy

    pFad v3 Proxy

    pFad v4 Proxy