Browse Source

Collection of misc. fixes from porting to a new platform (#161)

* Fix nullptr dereference if no info_queue in TestFramework renderer
* Use std::streamoff in StateRecorder. This is the correct type for tellg/seekg
* Cast pos_type -> size_t in ReadData
* Ensure LockFreeHashMap's mBuckets is aligned to 16
Joshie 3 years ago
parent
commit
662a0dfefc

+ 1 - 0
Jolt/Core/LockFreeHashMap.h

@@ -3,6 +3,7 @@
 
 #pragma once
 
+#include <Jolt/Core/Memory.h>
 #include <Jolt/Core/NonCopyable.h>
 
 JPH_SUPPRESS_WARNINGS_STD_BEGIN

+ 2 - 2
Jolt/Core/LockFreeHashMap.inl

@@ -114,7 +114,7 @@ void LockFreeHashMap<Key, Value>::Init(uint32 inMaxBuckets)
 	mNumBuckets = inMaxBuckets;
 	mMaxBuckets = inMaxBuckets;
 
-	mBuckets = new atomic<uint32> [inMaxBuckets];
+	mBuckets = reinterpret_cast<atomic<uint32> *>(AlignedAlloc(inMaxBuckets * sizeof(atomic<uint32>), 16));
 
 	Clear();
 }
@@ -122,7 +122,7 @@ void LockFreeHashMap<Key, Value>::Init(uint32 inMaxBuckets)
 template <class Key, class Value>
 LockFreeHashMap<Key, Value>::~LockFreeHashMap()
 {
-	delete [] mBuckets;
+	AlignedFree(mBuckets);
 }
 
 template <class Key, class Value>

+ 3 - 3
Jolt/Physics/StateRecorderImpl.cpp

@@ -50,12 +50,12 @@ bool StateRecorderImpl::IsEqual(StateRecorderImpl &inReference)
 {	
 	// Get length of new state
 	mStream.seekg(0, stringstream::end);
-	size_t this_len = mStream.tellg();
+	std::streamoff this_len = mStream.tellg();
 	mStream.seekg(0, stringstream::beg);
 
 	// Get length of old state
 	inReference.mStream.seekg(0, stringstream::end);
-	size_t reference_len = inReference.mStream.tellg();
+	std::streamoff reference_len = inReference.mStream.tellg();
 	inReference.mStream.seekg(0, stringstream::beg);
 
 	// Compare size
@@ -67,7 +67,7 @@ bool StateRecorderImpl::IsEqual(StateRecorderImpl &inReference)
 	}
 
 	// Compare byte by byte
-	for (size_t i = 0, l = this_len; !fail && i < l; ++i)
+	for (std::streamoff i = 0, l = this_len; !fail && i < l; ++i)
 	{
 		fail = inReference.mStream.get() != mStream.get();
 		if (fail)

+ 12 - 12
TestFramework/Renderer/Renderer.cpp

@@ -251,18 +251,18 @@ void Renderer::Initialize()
 		info_queue->SetBreakOnSeverity(D3D12_MESSAGE_SEVERITY_CORRUPTION, TRUE);
 		info_queue->SetBreakOnSeverity(D3D12_MESSAGE_SEVERITY_ERROR, TRUE);
 		info_queue->SetBreakOnSeverity(D3D12_MESSAGE_SEVERITY_WARNING, TRUE);
-	}
 
-	// Disable an error that triggers on Windows 11 with a hybrid graphic system
-	// See: https://stackoverflow.com/questions/69805245/directx-12-application-is-crashing-in-windows-11
-	D3D12_MESSAGE_ID hide[] =
-	{
-		D3D12_MESSAGE_ID_RESOURCE_BARRIER_MISMATCHING_COMMAND_LIST_TYPE,
-	};
-	D3D12_INFO_QUEUE_FILTER filter = { };
-	filter.DenyList.NumIDs = static_cast<UINT>(std::size(hide));
-	filter.DenyList.pIDList = hide;
-	info_queue->AddStorageFilterEntries(&filter);
+		// Disable an error that triggers on Windows 11 with a hybrid graphic system
+		// See: https://stackoverflow.com/questions/69805245/directx-12-application-is-crashing-in-windows-11
+		D3D12_MESSAGE_ID hide[] =
+		{
+			D3D12_MESSAGE_ID_RESOURCE_BARRIER_MISMATCHING_COMMAND_LIST_TYPE,
+		};
+		D3D12_INFO_QUEUE_FILTER filter = { };
+		filter.DenyList.NumIDs = static_cast<UINT>( std::size( hide ) );
+		filter.DenyList.pIDList = hide;
+		info_queue->AddStorageFilterEntries( &filter );
+	}
 #endif // _DEBUG
 
 	// Disable full screen transitions
@@ -786,7 +786,7 @@ void Renderer::CopyD3DResource(ID3D12Resource *inDest, const void *inSrc, uint64
 	void *data;
 	D3D12_RANGE range = { 0, 0 }; // We're not going to read
 	FatalErrorIfFailed(inDest->Map(0, &range, &data));
-	memcpy(data, inSrc, inSize);
+	memcpy(data, inSrc, size_t(inSize));
 	inDest->Unmap(0, nullptr);
 }
 

+ 1 - 1
TestFramework/Utils/ReadData.cpp

@@ -16,7 +16,7 @@ vector<uint8> ReadData(const char *inFileName)
 	input.seekg(0, ios_base::end);
 	ifstream::pos_type length = input.tellg();
 	input.seekg(0, ios_base::beg);
-	data.resize(length);
+	data.resize(size_t(length));
 	input.read((char *)&data[0], length);
 	if (!input)
 		FatalError("Unable to read file: %s", inFileName);