/// <summary> /// Disposes of any resources owned by the class. If you override this type, /// you should call base.Dispose(disposing) and not dispose any parents resources /// </summary> protected virtual void Dispose(bool disposing) { if (disposing) { _resource.Dispose(); } }
public void Reset() { resource.Dispose(); allocation.Dispose(); size = UINT64_MAX; dataSeed = 0; }
public void Dispose() { if (_pApplication != null) { _pApplication.Dispose(); } }
public static ComPtr<IDiaSymbol> GetSymbol(this IDiaSymbol symbol, SymTagEnum symTag, string name, Predicate<IDiaSymbol> filter = null) { var result = new ComPtr<IDiaSymbol>(); IDiaEnumSymbols enumSymbols; symbol.findChildren(symTag, name, 1, out enumSymbols); using (ComPtr.Create(enumSymbols)) { int n = enumSymbols.count; if (n == 0) { Debug.Fail("Symbol '" + name + "' was not found."); throw new ArgumentException(); } try { for (int i = 0; i < n; ++i) { using (var item = ComPtr.Create(enumSymbols.Item((uint)i))) { if (filter == null || filter(item.Object)) { if (result.Object == null) { result = item.Detach(); } else { Debug.Fail("Found more than one symbol named '" + name + "' and matching the filter."); throw new ArgumentException(); } } } } } catch { result.Dispose(); throw; } } return result; }
public static void Terminate() { if (IsInitialized) { Logger.Trace <ID3D11Device>("Disposing managers"); ReleaseBackbuffer(); BufferManager.Dispose(); BufferManager = null; TextureManager.Dispose(); TextureManager = null; SamplerManager.Dispose(); SamplerManager = null; ShaderManager.Dispose(); ShaderManager = null; RasterizerManager.Dispose(); RasterizerManager = null; SwapChain.Dispose(); SwapChain = null; Logger.Trace <ID3D11Device>("Disposing resources"); _swapChain.Dispose(); _context.Dispose(); _device.Dispose(); } IsInitialized = false; }
public static void Shutdown() { if (_windowMediator != null) { _windowMediator.Dispose(); } _windowMediator = null; }
public static void Shutdown() { if (_watcher != null) { _watcher.Dispose(); } _watcher = null; }
public void Dispose() { if (_branch != null) { _branch.Dispose(); } _branch = null; GC.SuppressFinalize(this); }
public void Dispose() { for (var i = 0; i < _sourceVoices.Length; ++i) { _sourceVoices[i].Dispose(); } _masteringVoice->DestroyVoice(); _xAudio2.Dispose(); }
public static void Shutdown() { if (_prefService != null) { _prefService.Dispose(); } if (_user != null) { _user.Dispose(); } if (_default != null) { _default.Dispose(); } _prefService = null; _user = null; _default = null; }
public static ComPtr <IDiaSymbol> GetSymbol(this IDiaSymbol symbol, SymTagEnum symTag, string name, Predicate <IDiaSymbol> filter = null) { ComPtr <IDiaSymbol> result = new ComPtr <IDiaSymbol>(); symbol.findChildren(symTag, name, 1, out IDiaEnumSymbols enumSymbols); using (ComPtr.Create(enumSymbols)) { int n = enumSymbols.count; if (n == 0) { Debug.Fail("Symbol '" + name + "' was not found."); throw new ArgumentException(); } try { for (int i = 0; i < n; ++i) { using (ComPtr <T> item = ComPtr.Create(enumSymbols.Item((uint)i))) { if (filter == null || filter(item.Object)) { if (result.Object == null) { result = item.Detach(); } else { Debug.Fail("Found more than one symbol named '" + name + "' and matching the filter."); throw new ArgumentException(); } } } } } catch { result.Dispose(); throw; } } return(result); }
public void ResourceFromBuffer(Device device, Type bufferType) { using Buffer <float> buffer = device.Get().AllocateBuffer <float>(bufferType, 128); using ComPtr <ID3D12Resource> d3D12Resource = default; InteropServices.GetID3D12Resource(buffer, FX.__uuidof <ID3D12Resource>(), (void **)d3D12Resource.GetAddressOf()); Assert.IsTrue(d3D12Resource.Get() != null); Assert.AreEqual(d3D12Resource.Get()->GetDesc().Dimension, D3D12_RESOURCE_DIMENSION_BUFFER); d3D12Resource.Dispose(); int hResult = InteropServices.TryGetID3D12Resource(buffer, FX.__uuidof <ID3D12Resource>(), (void **)d3D12Resource.GetAddressOf()); Assert.AreEqual(hResult, FX.S_OK); Assert.IsTrue(d3D12Resource.Get() != null); Assert.AreEqual(d3D12Resource.Get()->GetDesc().Dimension, D3D12_RESOURCE_DIMENSION_BUFFER); }
public void ResourceFromTexture3D(Device device, Type bufferType) { using Texture3D <float> buffer = device.Get().AllocateTexture3D <float>(bufferType, 16, 16, 4); using ComPtr <ID3D12Resource> d3D12Resource = default; InteropServices.GetID3D12Resource(buffer, Windows.__uuidof <ID3D12Resource>(), (void **)d3D12Resource.GetAddressOf()); Assert.IsTrue(d3D12Resource.Get() != null); Assert.AreEqual(d3D12Resource.Get()->GetDesc().Dimension, D3D12_RESOURCE_DIMENSION_TEXTURE3D); d3D12Resource.Dispose(); int hResult = InteropServices.TryGetID3D12Resource(buffer, Windows.__uuidof <ID3D12Resource>(), (void **)d3D12Resource.GetAddressOf()); Assert.AreEqual(hResult, S.S_OK); Assert.IsTrue(d3D12Resource.Get() != null); Assert.AreEqual(d3D12Resource.Get()->GetDesc().Dimension, D3D12_RESOURCE_DIMENSION_TEXTURE3D); }
/// <summary/> private void Dispose(bool fDisposing) { System.Diagnostics.Debug.WriteLineIf(!fDisposing, "****** Missing Dispose() call for " + GetType() + ". *******"); if (fDisposing && !IsDisposed) { // dispose managed and unmanaged objects if (webNav != null) { webNav.Dispose(); } if (command != null) { command.Dispose(); } _isInitialized = false; } webNav = null; command = null; IsDisposed = true; }
private bool ConnectToSolidEdge() { ComPtr pApplication = IntPtr.Zero; try { if (MarshalEx.Succeeded(MarshalEx.GetActiveObject("SolidEdge.Application", out pApplication))) { _application = pApplication.TryGetUniqueRCW <SolidEdgeFramework.Application>(); _connectionPointController.AdviseSink <SolidEdgeFramework.ISEApplicationEvents>(_application); commandBrowser.ActiveEnvironment = _application.GetActiveEnvironment(); globalParameterBrowser.RefreshGlobalParameters(); objectBrowser.Connect(); // Older versions of Solid Edge don't have the ProcessID property. try { processBrowser.ProcessId = _application.ProcessID; } catch { } return(true); } } catch { GlobalExceptionHandler.HandleException(); } finally { pApplication.Dispose(); } return(false); }
public void GetDevice(Device device) { using ComPtr <ID3D12Device> d3D12Device = default; InteropServices.GetID3D12Device(device.Get(), Windows.__uuidof <ID3D12Device>(), (void **)d3D12Device.GetAddressOf()); Assert.IsTrue(d3D12Device.Get() != null); LUID luid = d3D12Device.Get()->GetAdapterLuid(); Assert.IsTrue(*(ulong *)&luid != 0); d3D12Device.Dispose(); int hResult = InteropServices.TryGetID3D12Device(device.Get(), Windows.__uuidof <ID3D12Device>(), (void **)d3D12Device.GetAddressOf()); Assert.AreEqual(hResult, S.S_OK); Assert.IsTrue(d3D12Device.Get() != null); luid = d3D12Device.Get()->GetAdapterLuid(); Assert.IsTrue(*(ulong *)&luid != 0); }
private void Close() { _sound.Dispose(); }
protected sealed override void InternalDispose() { base.InternalDispose(); _device.Dispose(); }
public void Dispose() { _cacheEntryInfo.Dispose(); GC.SuppressFinalize(this); }
static void InitializeDirect3D() { var desc = new DXGI_SWAP_CHAIN_DESC { BufferDesc = new DXGI_MODE_DESC { Width = WIDTH, Height = HEIGHT, Format = DXGI_FORMAT_R8G8B8A8_UNORM, }, SampleDesc = new DXGI_SAMPLE_DESC { Count = 1 }, BufferCount = 1, Windowed = TRUE, OutputWindow = form.Handle, BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT, Flags = (uint)DXGI_SWAP_CHAIN_FLAG.DXGI_SWAP_CHAIN_FLAG_ALLOW_MODE_SWITCH }; uint creationFlags = 0; #if DEBUG creationFlags |= (uint)D3D11_CREATE_DEVICE_FLAG.D3D11_CREATE_DEVICE_DEBUG; #endif fixed(IDXGISwapChain **swapchain = &_swapchain) fixed(ID3D11Device **device = &_d3dDevice) fixed(ID3D11DeviceContext **context = &_d3dctx) { ThrowIfFailed(D3D11CreateDeviceAndSwapChain(null, D3D_DRIVER_TYPE_HARDWARE, IntPtr.Zero, creationFlags, null, 0, D3D11_SDK_VERSION, &desc, swapchain, device, null, context)); } ID3D10Multithread *pMultithread; var iid = IID_ID3D10Multithread; ThrowIfFailed(_d3dDevice->QueryInterface(&iid, (void **)&pMultithread)); pMultithread->SetMultithreadProtected(TRUE); pMultithread->Release(); var viewport = new D3D11_VIEWPORT { Height = HEIGHT, Width = WIDTH }; _d3dctx->RSSetViewports(1, &viewport); fixed(ID3D11Device **device = &_d3deviceVLC) fixed(ID3D11DeviceContext **context = &_d3dctxVLC) { ThrowIfFailed(D3D11CreateDevice(null, D3D_DRIVER_TYPE_HARDWARE, IntPtr.Zero, creationFlags | (uint)D3D11_CREATE_DEVICE_FLAG.D3D11_CREATE_DEVICE_VIDEO_SUPPORT, /* needed for hardware decoding */ null, 0, D3D11_SDK_VERSION, device, null, context)); } using ComPtr <ID3D11Resource> pBackBuffer = null; iid = IID_ID3D11Texture2D; ThrowIfFailed(_swapchain->GetBuffer(0, &iid, (void **)pBackBuffer.GetAddressOf())); fixed(ID3D11RenderTargetView **swapchainRenderTarget = &_swapchainRenderTarget) ThrowIfFailed(_d3dDevice->CreateRenderTargetView(pBackBuffer.Get(), null, swapchainRenderTarget)); pBackBuffer.Dispose(); fixed(ID3D11RenderTargetView **swapchainRenderTarget = &_swapchainRenderTarget) _d3dctx->OMSetRenderTargets(1, swapchainRenderTarget, null); ID3DBlob *VS, PS, pErrBlob; using ComPtr <ID3DBlob> vertexShaderBlob = null; fixed(byte *shader = Encoding.ASCII.GetBytes(DefaultShaders.HLSL)) fixed(byte *vshader = Encoding.ASCII.GetBytes("VShader")) fixed(byte *vs4 = Encoding.ASCII.GetBytes("vs_4_0")) fixed(byte *pshader = Encoding.ASCII.GetBytes("PShader")) fixed(byte *ps4 = Encoding.ASCII.GetBytes("ps_4_0")) { var result = D3DCompile(shader, (nuint)DefaultShaders.HLSL.Length, null, null, null, (sbyte *)vshader, (sbyte *)vs4, 0, 0, &VS, &pErrBlob); if (FAILED(result) && pErrBlob != null) { var errorMessage = Encoding.ASCII.GetString((byte *)pErrBlob->GetBufferPointer(), (int)pErrBlob->GetBufferSize()); Debug.WriteLine(errorMessage); ThrowIfFailed(result); } result = D3DCompile(shader, (nuint)DefaultShaders.HLSL.Length, null, null, null, (sbyte *)pshader, (sbyte *)ps4, 0, 0, &PS, &pErrBlob); if (FAILED(result) && pErrBlob != null) { var errorMessage = Encoding.ASCII.GetString((byte *)pErrBlob->GetBufferPointer(), (int)pErrBlob->GetBufferSize()); Debug.WriteLine(errorMessage); ThrowIfFailed(result); } } fixed(ID3D11VertexShader **vertexShader = &pVS) fixed(ID3D11PixelShader **pixelShader = &pPS) { ThrowIfFailed(_d3dDevice->CreateVertexShader(VS->GetBufferPointer(), VS->GetBufferSize(), null, vertexShader)); ThrowIfFailed(_d3dDevice->CreatePixelShader(PS->GetBufferPointer(), PS->GetBufferSize(), null, pixelShader)); } fixed(byte *position = Encoding.ASCII.GetBytes("POSITION")) fixed(byte *textcoord = Encoding.ASCII.GetBytes("TEXCOORD")) fixed(ID3D11InputLayout **shadersInputLayout = &pShadersInputLayout) { var inputElementDescs = stackalloc D3D11_INPUT_ELEMENT_DESC[2]; { inputElementDescs[0] = new D3D11_INPUT_ELEMENT_DESC { SemanticName = (sbyte *)position, SemanticIndex = 0, Format = DXGI_FORMAT_R32G32B32_FLOAT, InputSlot = 0, AlignedByteOffset = D3D11_APPEND_ALIGNED_ELEMENT, InputSlotClass = D3D11_INPUT_PER_VERTEX_DATA, InstanceDataStepRate = 0 }; inputElementDescs[1] = new D3D11_INPUT_ELEMENT_DESC { SemanticName = (sbyte *)textcoord, SemanticIndex = 0, Format = DXGI_FORMAT_R32G32_FLOAT, InputSlot = 0, AlignedByteOffset = D3D11_APPEND_ALIGNED_ELEMENT, InputSlotClass = D3D11_INPUT_PER_VERTEX_DATA, InstanceDataStepRate = 0 }; } ThrowIfFailed(_d3dDevice->CreateInputLayout(inputElementDescs, 2, VS->GetBufferPointer(), VS->GetBufferSize(), shadersInputLayout)); } var ourVerticles = new ShaderInput[4]; ourVerticles[0] = new ShaderInput { position = new Position { x = BORDER_LEFT, y = BORDER_BOTTOM, z = 0.0f }, texture = new Texture { x = 0.0f, y = 1.0f } }; ourVerticles[1] = new ShaderInput { position = new Position { x = BORDER_RIGHT, y = BORDER_BOTTOM, z = 0.0f }, texture = new Texture { x = 1.0f, y = 1.0f } }; ourVerticles[2] = new ShaderInput { position = new Position { x = BORDER_RIGHT, y = BORDER_TOP, z = 0.0f }, texture = new Texture { x = 1.0f, y = 0.0f } }; ourVerticles[3] = new ShaderInput { position = new Position { x = BORDER_LEFT, y = BORDER_TOP, z = 0.0f }, texture = new Texture { x = 0.0f, y = 0.0f } }; var verticlesSize = (uint)sizeof(ShaderInput) * 4; var bd = new D3D11_BUFFER_DESC { Usage = D3D11_USAGE_DYNAMIC, ByteWidth = verticlesSize, BindFlags = (uint)D3D11_BIND_VERTEX_BUFFER, CPUAccessFlags = (uint)D3D11_CPU_ACCESS_WRITE }; pVertexBuffer = CreateBuffer(bd); vertexBufferStride = Marshal.SizeOf(ourVerticles[0]); D3D11_MAPPED_SUBRESOURCE ms; ID3D11Resource *res; iid = IID_ID3D11Resource; ThrowIfFailed(pVertexBuffer->QueryInterface(&iid, (void **)&res)); ThrowIfFailed(_d3dctx->Map(res, 0, D3D11_MAP_WRITE_DISCARD, 0, &ms)); for (var i = 0; i < ourVerticles.Length; i++) { Marshal.StructureToPtr(ourVerticles[i], (IntPtr)ms.pData + (i * vertexBufferStride), false); } //Buffer.MemoryCopy(ms.pData, ourVerticles, verticlesSize, verticlesSize); _d3dctx->Unmap(res, 0); quadIndexCount = 6; var bufferDesc = new D3D11_BUFFER_DESC { Usage = D3D11_USAGE_DYNAMIC, ByteWidth = sizeof(ushort) * quadIndexCount, BindFlags = (uint)D3D11_BIND_INDEX_BUFFER, CPUAccessFlags = (uint)D3D11_CPU_ACCESS_WRITE }; pIndexBuffer = CreateBuffer(bufferDesc); ThrowIfFailed(pIndexBuffer->QueryInterface(&iid, (void **)&res)); ThrowIfFailed(_d3dctx->Map(res, 0, D3D11_MAP_WRITE_DISCARD, 0, &ms)); Marshal.WriteInt16((IntPtr)ms.pData, 0 * sizeof(ushort), 3); Marshal.WriteInt16((IntPtr)ms.pData, 1 * sizeof(ushort), 1); Marshal.WriteInt16((IntPtr)ms.pData, 2 * sizeof(ushort), 0); Marshal.WriteInt16((IntPtr)ms.pData, 3 * sizeof(ushort), 2); Marshal.WriteInt16((IntPtr)ms.pData, 4 * sizeof(ushort), 1); Marshal.WriteInt16((IntPtr)ms.pData, 5 * sizeof(ushort), 3); _d3dctx->Unmap(res, 0); _d3dctx->IASetPrimitiveTopology(D3D10_PRIMITIVE_TOPOLOGY_TRIANGLELIST); _d3dctx->IASetInputLayout(pShadersInputLayout); uint offset = 0; var vv = (uint)vertexBufferStride; fixed(ID3D11Buffer **buffer = &pVertexBuffer) _d3dctx->IASetVertexBuffers(0, 1, buffer, &vv, &offset); _d3dctx->IASetIndexBuffer(pIndexBuffer, DXGI_FORMAT_R16_UINT, 0); _d3dctx->VSSetShader(pVS, null, 0); _d3dctx->PSSetShader(pPS, null, 0); var samplerDesc = new D3D11_SAMPLER_DESC { Filter = D3D11_FILTER_MIN_MAG_LINEAR_MIP_POINT, AddressU = D3D11_TEXTURE_ADDRESS_CLAMP, AddressV = D3D11_TEXTURE_ADDRESS_CLAMP, AddressW = D3D11_TEXTURE_ADDRESS_CLAMP, ComparisonFunc = D3D11_COMPARISON_ALWAYS, MinLOD = 0, MaxLOD = D3D11_FLOAT32_MAX }; fixed(ID3D11SamplerState **ss = &samplerState) { ThrowIfFailed(_d3dDevice->CreateSamplerState(&samplerDesc, ss)); _d3dctx->PSSetSamplers(0, 1, ss); } fixed(RTL_CRITICAL_SECTION *sl = &sizeLock) InitializeCriticalSection(sl); }
/// <inheritdoc cref="IDisposable"/> public void Dispose() { _value.Dispose(); }
private void Window_Closed(object sender, WindowEventArgs args) { m_swapChain.Dispose(); m_swapChainNative.Dispose(); }
public void Dispose() { _queue.Dispose(); _fence.Dispose(); }
/// <inheritdoc cref="IDisposable"/> public void Dispose() => _adapter.Dispose();
/// <inheritdoc cref="IDisposable"/> public void Dispose() => _output.Dispose();
public static bool RememberRecentBadCert(Uri url) { if (url == null) { throw new ArgumentNullException("url"); } ComPtr <nsISSLStatus> aSSLStatus = null; try { int port = url.Port; if (port == -1) { port = 443; } using (var hostWithPort = new nsAString(url.Host + ":" + port.ToString())) { using (var certDbSvc = Xpcom.GetService2 <nsIX509CertDB>(Contracts.X509CertDb)) { if (certDbSvc != null) { using (var recentBadCerts = certDbSvc.Instance.GetRecentBadCerts(false).AsComPtr()) { if (recentBadCerts != null) { aSSLStatus = recentBadCerts.Instance.GetRecentBadCert(hostWithPort).AsComPtr(); } } } } } using (var cert = aSSLStatus.Instance.GetServerCertAttribute().AsComPtr()) { if (aSSLStatus == null || HasMatchingOverride(url, cert)) { return(false); } int flags = 0; if (aSSLStatus.Instance.GetIsUntrustedAttribute()) { flags |= nsICertOverrideServiceConsts.ERROR_UNTRUSTED; } if (aSSLStatus.Instance.GetIsDomainMismatchAttribute()) { flags |= nsICertOverrideServiceConsts.ERROR_MISMATCH; } if (aSSLStatus.Instance.GetIsNotValidAtThisTimeAttribute()) { flags |= nsICertOverrideServiceConsts.ERROR_TIME; } RememberValidityOverride(url, cert, flags); } } finally { if (aSSLStatus != null) { aSSLStatus.Dispose(); } } return(true); }
/// <inheritdoc cref="IDisposable"/> public void Dispose() { _factory.Dispose(); }
/// <inheritdoc cref="IComType.Dispose"/> public void Dispose() => _heap.Dispose();
private void SwapChain_SizeChanged(object sender, SizeChangedEventArgs e) { uint width, height; if (sender is Tuple <double, double> size) { width = (uint)size.Item1; height = (uint)size.Item2; } else { width = (uint)e.NewSize.Width; height = (uint)e.NewSize.Height; } if (width <= 0 || height <= 0) { return; } InitPipeline(); m_d3dContext.Get()->ClearState(); m_renderTargetView.Dispose(); m_depthStencilView.Dispose(); m_renderTargetView = new ComPtr <ID3D11RenderTargetView>(); m_depthStencilView = new ComPtr <ID3D11DepthStencilView>(); // resize the swap chain int hr = m_swapChain.Get()->ResizeBuffers( 0, // Don't change buffer count width, height, DXGI_FORMAT.DXGI_FORMAT_UNKNOWN, // Don't change format 0 // No flags ); Marshal.ThrowExceptionForHR(hr); // (re)-create the render target view ComPtr <ID3D11Texture2D> backBuffer = new ComPtr <ID3D11Texture2D>(); var d3d11Text2D = typeof(ID3D11Texture2D).GUID; D3D11_RENDER_TARGET_VIEW_DESC desc = new D3D11_RENDER_TARGET_VIEW_DESC { ViewDimension = D3D11_RTV_DIMENSION.D3D11_RTV_DIMENSION_BUFFER }; m_renderTargetView = new ComPtr <ID3D11RenderTargetView>(); if (FAILED(m_swapChain.Get()->GetBuffer(0, InteropUtilities.AsPointer(ref d3d11Text2D), (void **)backBuffer.GetAddressOf()))) { throw new Exception("Direct3D was unable to acquire the back buffer!"); } if (FAILED(m_d3dDevice.Get()->CreateRenderTargetView( (ID3D11Resource *)backBuffer.Get(), null, m_renderTargetView.GetAddressOf()))) { throw new Exception("Direct3D was unable to create the render target view!"); } // create the depth and stencil buffer D3D11_TEXTURE2D_DESC dsd; ComPtr <ID3D11Texture2D> dsBuffer = new ComPtr <ID3D11Texture2D>(); backBuffer.Get()->GetDesc(&dsd); dsd.Format = DXGI_FORMAT.DXGI_FORMAT_D24_UNORM_S8_UINT; dsd.Usage = D3D11_USAGE.D3D11_USAGE_DEFAULT; dsd.BindFlags = (uint)D3D11_BIND_FLAG.D3D11_BIND_DEPTH_STENCIL; if (FAILED(m_d3dDevice.Get()->CreateTexture2D(&dsd, null, dsBuffer.GetAddressOf()))) { throw new Exception("Direct3D was unable to create a 2D-texture!"); } if (FAILED(m_d3dDevice.Get()->CreateDepthStencilView((ID3D11Resource *)dsBuffer.Get(), null, m_depthStencilView.GetAddressOf()))) { throw new Exception("Direct3D was unable to create the depth and stencil buffer!"); } // activate the depth and stencil buffer m_d3dContext.Get()->OMSetRenderTargets(1, m_renderTargetView.GetAddressOf(), m_depthStencilView.Get()); // set the viewport to the entire backbuffer D3D11_VIEWPORT vp; vp.TopLeftX = 0; vp.TopLeftY = 0; vp.Width = dsd.Width; vp.Height = dsd.Height; vp.MinDepth = 0.0f; vp.MaxDepth = 1.0f; m_d3dContext.Get()->RSSetViewports(1, &vp); Present(); //m_renderTargetView.Get()->Release(); backBuffer.Get()->Release(); }
protected override void OnClose() { _symbol.Dispose(); base.OnClose(); }
/// <inheritdoc/> public void Dispose() { _pso.Dispose(); }