Repository: xbmc/xbmc
File: xbmc/guilib/D3DResource.h (C/C++)

Code before:
  bool SetResources(LPCSTR handle, ID3D11ShaderResourceView** ppSRViews, size_t count);
  bool SetConstantBuffer(LPCSTR handle, ID3D11Buffer *buffer);
  bool SetScalar(LPCSTR handle, float value);
  void AddIncludePath(const std::string& includePath);
  bool Begin(UINT *passes, DWORD flags);
  bool BeginPass(UINT pass);
  bool EndPass();
  bool End();

  ID3DX11Effect* Get() const { return m_effect.Get(); }

  void OnDestroyDevice(bool fatal) override;
  void OnCreateDevice() override;

  // ID3DInclude interface
  __declspec(nothrow) HRESULT __stdcall Open(D3D_INCLUDE_TYPE IncludeType, LPCSTR pFileName, LPCVOID pParentData, LPCVOID *ppData, UINT *pBytes) override;
  __declspec(nothrow) HRESULT __stdcall Close(LPCVOID pData) override;

private:
  bool CreateEffect();

  std::string m_effectString;
  DefinesMap m_defines;
  Microsoft::WRL::ComPtr<ID3DX11Effect> m_effect{nullptr};
  Microsoft::WRL::ComPtr<ID3DX11EffectTechnique> m_techniquie{nullptr};
  Microsoft::WRL::ComPtr<ID3DX11EffectPass> m_currentPass{nullptr};
  std::set<std::string> m_includePaths;
};

class CD3DBuffer : public ID3DResource
{
public:
  CD3DBuffer();
  virtual ~CD3DBuffer();
  bool Create(D3D11_BIND_FLAG type, UINT count, UINT stride, DXGI_FORMAT format, D3D11_USAGE usage, const void* initData = nullptr);
  bool Map(void** resource);
  bool Unmap();
  void Release();
  unsigned int GetStride() { return m_stride; }
  DXGI_FORMAT GetFormat() { return m_format; }
  ID3D11Buffer* Get() const { return m_buffer.Get(); }

  void OnDestroyDevice(bool fatal) override;
  void OnCreateDevice() override;

private:
  bool CreateBuffer(const void *pData);

  // saved data
  BYTE* m_data;
  UINT m_length{0};

Review comment (bug):
`ComPtr` is already initialized to nullptr by default.

Here and all others.

Code after:
  bool SetResources(LPCSTR handle, ID3D11ShaderResourceView** ppSRViews, size_t count);
  bool SetConstantBuffer(LPCSTR handle, ID3D11Buffer *buffer);
  bool SetScalar(LPCSTR handle, float value);
  void AddIncludePath(const std::string& includePath);
  bool Begin(UINT *passes, DWORD flags);
  bool BeginPass(UINT pass);
  bool EndPass();
  bool End();

  ID3DX11Effect* Get() const { return m_effect.Get(); }

  void OnDestroyDevice(bool fatal) override;
  void OnCreateDevice() override;

  // ID3DInclude interface
  __declspec(nothrow) HRESULT __stdcall Open(D3D_INCLUDE_TYPE IncludeType, LPCSTR pFileName, LPCVOID pParentData, LPCVOID *ppData, UINT *pBytes) override;
  __declspec(nothrow) HRESULT __stdcall Close(LPCVOID pData) override;

private:
  bool CreateEffect();

  std::string m_effectString;
  DefinesMap m_defines;
  Microsoft::WRL::ComPtr<ID3DX11Effect> m_effect;
  Microsoft::WRL::ComPtr<ID3DX11EffectTechnique> m_techniquie;
  Microsoft::WRL::ComPtr<ID3DX11EffectPass> m_currentPass;
  std::set<std::string> m_includePaths;
};

class CD3DBuffer : public ID3DResource
{
public:
  CD3DBuffer();
  virtual ~CD3DBuffer();
  bool Create(D3D11_BIND_FLAG type, UINT count, UINT stride, DXGI_FORMAT format, D3D11_USAGE usage, const void* initData = nullptr);
  bool Map(void** resource);
  bool Unmap();
  void Release();
  unsigned int GetStride() { return m_stride; }
  DXGI_FORMAT GetFormat() { return m_format; }
  ID3D11Buffer* Get() const { return m_buffer.Get(); }

  void OnDestroyDevice(bool fatal) override;
  void OnCreateDevice() override;

private:
  bool CreateBuffer(const void *pData);

  // saved data
  BYTE* m_data;
  UINT m_length{0};