Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion Audio/DynamicSoundEffectInstance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ class DynamicSoundEffectInstance::Impl : public IVoiceNotify
mBufferNeeded(nullptr),
mObject(object)
{
if (!engine)
throw std::invalid_argument("AudioEngine is required");

if ((sampleRate < XAUDIO2_MIN_SAMPLE_RATE)
|| (sampleRate > XAUDIO2_MAX_SAMPLE_RATE))
{
Expand All @@ -55,6 +58,12 @@ class DynamicSoundEffectInstance::Impl : public IVoiceNotify
throw std::invalid_argument("DynamicSoundEffectInstance supports 8 or 16 bit");
}

if (!bufferNeeded)
{
DebugTrace("DynamicSoundEffectInstance requires a valid callback\n");
throw std::invalid_argument("DynamicSoundEffectInstance");
}

mBufferEvent.reset(CreateEventEx(nullptr, nullptr, 0, EVENT_MODIFY_STATE | SYNCHRONIZE));
if (!mBufferEvent)
{
Expand All @@ -63,7 +72,6 @@ class DynamicSoundEffectInstance::Impl : public IVoiceNotify

CreateIntegerPCM(&mWaveFormat, sampleRate, channels, sampleBits);

assert(engine != nullptr);
engine->RegisterNotify(this, true);

mBase.Initialize(engine, &mWaveFormat, flags);
Expand Down
12 changes: 12 additions & 0 deletions Audio/SoundCommon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -521,6 +521,9 @@ void DirectX::CreateIntegerPCM(
int channels,
int sampleBits) noexcept
{
if (!wfx)
return;

const int blockAlign = channels * sampleBits / 8;

wfx->wFormatTag = WAVE_FORMAT_PCM;
Expand All @@ -541,6 +544,9 @@ void DirectX::CreateFloatPCM(
int sampleRate,
int channels) noexcept
{
if (!wfx)
return;

const int blockAlign = channels * 4;

wfx->wFormatTag = WAVE_FORMAT_IEEE_FLOAT;
Expand All @@ -563,6 +569,9 @@ void DirectX::CreateADPCM(
int channels,
int samplesPerBlock) noexcept(false)
{
if (!wfx)
return;

if (wfxSize < (sizeof(WAVEFORMATEX) + MSADPCM_FORMAT_EXTRA_BYTES))
{
DebugTrace("CreateADPCM needs at least %zu bytes for the result\n",
Expand Down Expand Up @@ -608,6 +617,9 @@ void DirectX::CreateXWMA(
int avgBytes,
bool wma3) noexcept
{
if (!wfx)
return;

wfx->wFormatTag = static_cast<WORD>((wma3) ? WAVE_FORMAT_WMAUDIO3 : WAVE_FORMAT_WMAUDIO2);
wfx->nChannels = static_cast<WORD>(channels);
wfx->nSamplesPerSec = static_cast<DWORD>(sampleRate);
Expand Down
2 changes: 2 additions & 0 deletions Audio/SoundCommon.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
#include "Audio.h"
#include "PlatformHelpers.h"

#include <stdexcept>

#ifdef USING_XAUDIO2_9
#define DIRECTX_ENABLE_XWMA
#endif
Expand Down
4 changes: 3 additions & 1 deletion Audio/SoundEffect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,9 @@ class SoundEffect::Impl : public IVoiceNotify
, mXMAMemory(nullptr)
#endif
{
assert(mEngine != nullptr);
if (!engine)
throw std::invalid_argument("AudioEngine is required");

mEngine->RegisterNotify(this, false);
}

Expand Down
4 changes: 3 additions & 1 deletion Audio/WaveBank.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ class WaveBank::Impl : public IVoiceNotify
mPrepared(false),
mStreaming(false)
{
assert(mEngine != nullptr);
if (!engine)
throw std::invalid_argument("AudioEngine is required");

mEngine->RegisterNotify(this, false);
}

Expand Down
14 changes: 10 additions & 4 deletions Audio/WaveBankReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -517,6 +517,9 @@ HRESULT WaveBankReader::Impl::Open(const wchar_t* szFileName) noexcept(false)
Close();
Clear();

if (!szFileName)
return E_INVALIDARG;

m_prepared = false;

m_event.reset(CreateEventEx(nullptr, nullptr, CREATE_EVENT_MANUAL_RESET, EVENT_MODIFY_STATE | SYNCHRONIZE));
Expand Down Expand Up @@ -1029,7 +1032,7 @@ HRESULT WaveBankReader::Impl::GetWaveData(uint32_t index, const uint8_t** pData,
#endif

if (!waveData)
return E_FAIL;
return E_POINTER;

if (m_data.dwFlags & BANKDATA::TYPE_STREAMING)
{
Expand Down Expand Up @@ -1223,10 +1226,13 @@ HRESULT WaveBankReader::Open(const wchar_t* szFileName) noexcept
_Use_decl_annotations_
uint32_t WaveBankReader::Find(const char* name) const
{
auto it = pImpl->m_names.find(name);
if (it != pImpl->m_names.cend())
if (name)
{
return it->second;
auto it = pImpl->m_names.find(name);
if (it != pImpl->m_names.cend())
{
return it->second;
}
}

return uint32_t(-1);
Expand Down
6 changes: 6 additions & 0 deletions Inc/DirectXHelpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,9 @@ namespace DirectX
_In_ const D3D12_ROOT_SIGNATURE_DESC* rootSignatureDesc,
_Out_ ID3D12RootSignature** rootSignature) noexcept
{
if (!device || !rootSignatureDesc || !rootSignature)
return E_INVALIDARG;

Microsoft::WRL::ComPtr<ID3DBlob> pSignature;
Microsoft::WRL::ComPtr<ID3DBlob> pError;
HRESULT hr = D3D12SerializeRootSignature(rootSignatureDesc, D3D_ROOT_SIGNATURE_VERSION_1, pSignature.GetAddressOf(), pError.GetAddressOf());
Expand All @@ -217,6 +220,9 @@ namespace DirectX
DIRECTX_TOOLKIT_API
inline XMUINT2 GetTextureSize(_In_ ID3D12Resource* tex) noexcept
{
if (!tex)
return XMUINT2(0, 0);

#if defined(_MSC_VER) || !defined(_WIN32)
const auto desc = tex->GetDesc();
#else
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ For a full change history, see [CHANGELOG.md](https://github.com/microsoft/Direc

## Support

For questions, consider using [Stack Overflow](https://stackoverflow.com/questions/tagged/directxtk) with the _directxtk_ tag, or the [DirectX Discord Server](https://discord.gg/directx) in the _dx12-developers_ channel.
For questions, consider using [Stack Overflow](https://stackoverflow.com/questions/tagged/directxtk) with the _directxtk_ tag, or the [DirectX Discord Server](https://discord.gg/directx) in the _dx12-developers_ or _input-and-audio_ channels.

For bug reports and feature requests, please use GitHub [issues](https://github.com/microsoft/DirectXTK12/issues) for this project.

Expand Down
3 changes: 3 additions & 0 deletions Src/BinaryReader.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ namespace DirectX
explicit BinaryReader(_In_z_ wchar_t const* fileName) noexcept(false);
BinaryReader(_In_reads_bytes_(dataSize) uint8_t const* dataBlob, size_t dataSize) noexcept;

BinaryReader(BinaryReader&&) noexcept;
BinaryReader& operator= (BinaryReader&&) noexcept;

BinaryReader(BinaryReader const&) = delete;
BinaryReader& operator= (BinaryReader const&) = delete;

Expand Down
3 changes: 3 additions & 0 deletions Src/CommonStates.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -456,6 +456,9 @@ class CommonStates::Impl
explicit Impl(_In_ ID3D12Device* device)
: mDescriptors(device, D3D12_DESCRIPTOR_HEAP_TYPE_SAMPLER, D3D12_DESCRIPTOR_HEAP_FLAG_SHADER_VISIBLE, static_cast<size_t>(SamplerIndex::Count))
{
if (!device)
throw std::invalid_argument("Direct3D device is null");

SetDebugObjectName(mDescriptors.Heap(), L"CommonStates");

for (size_t i = 0; i < static_cast<size_t>(SamplerIndex::Count); ++i)
Expand Down
15 changes: 15 additions & 0 deletions Src/DirectXHelpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ void DirectX::CreateShaderResourceView(
D3D12_CPU_DESCRIPTOR_HANDLE srvDescriptor,
bool isCubeMap)
{
if (!device || !tex)
throw std::invalid_argument("Direct3D device and resource must be valid");

#if defined(_MSC_VER) || !defined(_WIN32)
const auto desc = tex->GetDesc();
#else
Expand Down Expand Up @@ -109,6 +112,9 @@ void DirectX::CreateUnorderedAccessView(
D3D12_CPU_DESCRIPTOR_HANDLE uavDescriptor,
uint32_t mipLevel)
{
if (!device || !tex)
throw std::invalid_argument("Direct3D device and resource must be valid");

#if defined(_MSC_VER) || !defined(_WIN32)
const auto desc = tex->GetDesc();
#else
Expand Down Expand Up @@ -182,6 +188,9 @@ void DirectX::CreateRenderTargetView(
D3D12_CPU_DESCRIPTOR_HANDLE rtvDescriptor,
uint32_t mipLevel)
{
if (!device || !tex)
throw std::invalid_argument("Direct3D device and resource must be valid");

#if defined(_MSC_VER) || !defined(_WIN32)
const auto desc = tex->GetDesc();
#else
Expand Down Expand Up @@ -267,6 +276,9 @@ void DirectX::CreateBufferShaderResourceView(
D3D12_CPU_DESCRIPTOR_HANDLE srvDescriptor,
uint32_t stride)
{
if (!device || !buffer)
throw std::invalid_argument("Direct3D device and resource must be valid");

#if defined(_MSC_VER) || !defined(_WIN32)
const auto desc = buffer->GetDesc();
#else
Expand Down Expand Up @@ -304,6 +316,9 @@ void DirectX::CreateBufferUnorderedAccessView(
uint32_t counterOffset,
ID3D12Resource* counterResource)
{
if (!device || !buffer)
throw std::invalid_argument("Direct3D device and resource must be valid");

#if defined(_MSC_VER) || !defined(_WIN32)
const auto desc = buffer->GetDesc();
#else
Expand Down
3 changes: 3 additions & 0 deletions Src/PBREffectFactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,9 @@ class PBREffectFactory::Impl
, mSamplerDescriptors(nullptr)
, mDevice(device)
{
if (!device)
throw std::invalid_argument("Direct3D device is null");

if (textureDescriptors)
mTextureDescriptors = std::make_unique<DescriptorHeap>(textureDescriptors);
if (samplerDescriptors)
Expand Down
28 changes: 20 additions & 8 deletions Src/ResourceUploadBatch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -302,14 +302,16 @@ class ResourceUploadBatch::Impl
{
public:
Impl(
_In_ ID3D12Device* device) noexcept
_In_ ID3D12Device* device)
: mDevice(device)
, mCommandType(D3D12_COMMAND_LIST_TYPE_DIRECT)
, mInBeginEndBlock(false)
, mTypedUAVLoadAdditionalFormats(false)
, mStandardSwizzle64KBSupported(false)
{
assert(device != nullptr);
if (!device)
throw std::invalid_argument("Direct3D device is null");

D3D12_FEATURE_DATA_D3D12_OPTIONS options = {};
if (SUCCEEDED(device->CheckFeatureSupport(
D3D12_FEATURE_D3D12_OPTIONS,
Expand Down Expand Up @@ -358,7 +360,7 @@ class ResourceUploadBatch::Impl
}

// Asynchronously uploads a resource. The memory in subRes is copied.
// The resource must be in the COPY_DEST state.
// The resource must be in the COPY_DEST or COMMON state.
void Upload(
_In_ ID3D12Resource* resource,
uint32_t subresourceIndexStart,
Expand All @@ -368,6 +370,9 @@ class ResourceUploadBatch::Impl
if (!mInBeginEndBlock)
throw std::logic_error("Can't call Upload on a closed ResourceUploadBatch.");

if (!resource || !subRes || !numSubresources)
throw std::invalid_argument("Resource/subresource are null");

const UINT64 uploadSize = GetRequiredIntermediateSize(
resource,
subresourceIndexStart,
Expand Down Expand Up @@ -409,6 +414,9 @@ class ResourceUploadBatch::Impl
if (!mInBeginEndBlock)
throw std::logic_error("Can't call Upload on a closed ResourceUploadBatch.");

if (!resource)
throw std::invalid_argument("Resource is null");

// Submit resource copy to command list
mList->CopyBufferRegion(resource, 0, buffer.Resource(), buffer.ResourceOffset(), buffer.Size());

Expand All @@ -420,14 +428,12 @@ class ResourceUploadBatch::Impl
// Resource must be in the PIXEL_SHADER_RESOURCE state
void GenerateMips(_In_ ID3D12Resource* resource)
{
if (resource == nullptr)
{
throw std::invalid_argument("Nullptr passed to GenerateMips");
}

if (!mInBeginEndBlock)
throw std::logic_error("Can't call GenerateMips on a closed ResourceUploadBatch.");

if (!resource)
throw std::invalid_argument("GenerateMips resource is null");

if (mCommandType == D3D12_COMMAND_LIST_TYPE_COPY)
{
DebugTrace("ERROR: GenerateMips cannot operate on a copy queue\n");
Expand Down Expand Up @@ -508,6 +514,9 @@ class ResourceUploadBatch::Impl
if (!mInBeginEndBlock)
throw std::logic_error("Can't call Upload on a closed ResourceUploadBatch.");

if (!resource)
throw std::invalid_argument("Transition resource is null");

if (mCommandType == D3D12_COMMAND_LIST_TYPE_COPY)
{
switch (stateAfter)
Expand Down Expand Up @@ -551,6 +560,9 @@ class ResourceUploadBatch::Impl
if (!mInBeginEndBlock)
throw std::logic_error("ResourceUploadBatch already closed.");

if (!commandQueue)
throw std::invalid_argument("Direct3D queue is null");

ThrowIfFailed(mList->Close());

// Submit the job to the GPU
Expand Down
4 changes: 3 additions & 1 deletion Src/SpriteBatch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,7 @@ SpriteBatch::Impl::Impl(ID3D12Device* device,
mVertexSegment{},
mVertexPageSize(sizeof(VertexPositionColorTexture) * MaxBatchSize * VerticesPerSprite),
mSpriteCount(0),
mDeviceResources(deviceResourcesPool.DemandCreate(device, upload))
mDeviceResources{}
{
if (!device)
throw std::invalid_argument("Direct3D device is null");
Expand All @@ -455,6 +455,8 @@ SpriteBatch::Impl::Impl(ID3D12Device* device,
mSetViewport = true;
}

mDeviceResources = deviceResourcesPool.DemandCreate(device, upload);

D3D12_GRAPHICS_PIPELINE_STATE_DESC d3dDesc = {};
d3dDesc.InputLayout = s_DefaultInputLayoutDesc;
d3dDesc.BlendState = psoDesc.blendDesc;
Expand Down
5 changes: 5 additions & 0 deletions Src/SpriteFont.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,11 @@ SpriteFont::Impl::Impl(
lineSpacing(ilineSpacing),
utfBufferSize(0)
{
if (!itexture.ptr)
{
throw std::invalid_argument("Sprite sheet texture required");
}

if (!std::is_sorted(iglyphs, iglyphs + glyphCount))
{
throw std::runtime_error("Glyphs must be in ascending codepoint order");
Expand Down
2 changes: 1 addition & 1 deletion Src/ToneMapPostProcess.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ ToneMapPostProcess::Impl::Impl(_In_ ID3D12Device* device, const RenderTargetStat
if (op >= Operator_Max)
throw std::invalid_argument("Tonemap operator not defined");

if (func > TransferFunction_Max)
if (func >= TransferFunction_Max)
throw std::invalid_argument("Transfer function not defined");

if (!device)
Expand Down
Loading