소스 검색

Fixed crash when destructing a JobSystemThreadPool that never got an Init call (#484)

Jorrit Rouwe 2 년 전
부모
커밋
fadc299502
2개의 변경된 파일18개의 추가작업 그리고 8개의 파일을 삭제
  1. 12 8
      Jolt/Core/FixedSizeFreeList.inl
  2. 6 0
      TestFramework/Utils/CustomMemoryHook.cpp

+ 12 - 8
Jolt/Core/FixedSizeFreeList.inl

@@ -7,14 +7,18 @@ JPH_NAMESPACE_BEGIN
 template <typename Object>
 FixedSizeFreeList<Object>::~FixedSizeFreeList()
 {
-	// Ensure everything is freed before the freelist is destructed
-	JPH_ASSERT(mNumFreeObjects.load(memory_order_relaxed) == mNumPages * mPageSize);
-
-	// Free memory for pages
-	uint32 num_pages = mNumObjectsAllocated / mPageSize;
-	for (uint32 page = 0; page < num_pages; ++page)
-		AlignedFree(mPages[page]);
-	Free(mPages);
+	// Check if we got our Init call
+	if (mPages != nullptr)
+	{
+		// Ensure everything is freed before the freelist is destructed
+		JPH_ASSERT(mNumFreeObjects.load(memory_order_relaxed) == mNumPages * mPageSize);
+
+		// Free memory for pages
+		uint32 num_pages = mNumObjectsAllocated / mPageSize;
+		for (uint32 page = 0; page < num_pages; ++page)
+			AlignedFree(mPages[page]);
+		Free(mPages);
+	}
 }
 
 template <typename Object>

+ 6 - 0
TestFramework/Utils/CustomMemoryHook.cpp

@@ -36,6 +36,9 @@ struct InCustomAllocator
 // Add a tag to an allocation to track if it is aligned / unaligned
 static void *TagAllocation(void *inPointer, size_t inAlignment, char inMode)
 {
+	if (inPointer == nullptr)
+		return nullptr;
+
 	uint8 *p = reinterpret_cast<uint8 *>(inPointer);
 	*p = inMode;
 	return p + inAlignment;
@@ -44,6 +47,9 @@ static void *TagAllocation(void *inPointer, size_t inAlignment, char inMode)
 // Remove tag from allocation
 static void *UntagAllocation(void *inPointer, size_t inAlignment, char inMode)
 {
+	if (inPointer == nullptr)
+		return nullptr;
+
 	uint8 *p = reinterpret_cast<uint8 *>(inPointer) - inAlignment;
 	JPH_ASSERT(*p == inMode);
 	*p = 0;