Browse Source

Fixed emscripten debug build (#1201)

Jorrit Rouwe 1 year ago
parent
commit
20eedf47c4

+ 2 - 2
Build/README.md

@@ -194,8 +194,8 @@ To implement your custom memory allocator override Allocate, Free, Reallocate, A
 		<li>Install Emscripten (https://emscripten.org/docs/getting_started/downloads.html)</li>
 		<li>Install Emscripten (https://emscripten.org/docs/getting_started/downloads.html)</li>
 		<li>Install nodejs (apt-get install nodejs)</li>
 		<li>Install nodejs (apt-get install nodejs)</li>
 		<li>Download CMake 3.23+ (https://cmake.org/download/)</li>
 		<li>Download CMake 3.23+ (https://cmake.org/download/)</li>
-		<li>Run: ./cmake_linux_emscripten.sh Release (currently some unit tests fail in Debug for unknown reasons)</li>
-		<li>Go to the WASM_Release folder</li>
+		<li>Run: ./cmake_linux_emscripten.sh</li>
+		<li>Go to the WASM_Debug folder</li>
 		<li>Run: make -j$(nproc) && node UnitTests.js</li>
 		<li>Run: make -j$(nproc) && node UnitTests.js</li>
 	</ul>
 	</ul>
 </details>
 </details>

+ 3 - 1
Jolt/Core/JobSystemThreadPool.cpp

@@ -46,8 +46,9 @@ JobSystemThreadPool::JobSystemThreadPool(uint inMaxJobs, uint inMaxBarriers, int
 	Init(inMaxJobs, inMaxBarriers, inNumThreads);
 	Init(inMaxJobs, inMaxBarriers, inNumThreads);
 }
 }
 
 
-void JobSystemThreadPool::StartThreads(int inNumThreads)
+void JobSystemThreadPool::StartThreads([[maybe_unused]] int inNumThreads)
 {
 {
+#if !defined(JPH_CPU_WASM) || defined(__EMSCRIPTEN_PTHREADS__) // If we're running without threads support we cannot create threads and we ignore the inNumThreads parameter
 	// Auto detect number of threads
 	// Auto detect number of threads
 	if (inNumThreads < 0)
 	if (inNumThreads < 0)
 		inNumThreads = thread::hardware_concurrency() - 1;
 		inNumThreads = thread::hardware_concurrency() - 1;
@@ -69,6 +70,7 @@ void JobSystemThreadPool::StartThreads(int inNumThreads)
 	mThreads.reserve(inNumThreads);
 	mThreads.reserve(inNumThreads);
 	for (int i = 0; i < inNumThreads; ++i)
 	for (int i = 0; i < inNumThreads; ++i)
 		mThreads.emplace_back([this, i] { ThreadMain(i); });
 		mThreads.emplace_back([this, i] { ThreadMain(i); });
+#endif
 }
 }
 
 
 JobSystemThreadPool::~JobSystemThreadPool()
 JobSystemThreadPool::~JobSystemThreadPool()

+ 1 - 1
Jolt/Jolt.cmake

@@ -667,7 +667,7 @@ else()
 endif()
 endif()
 
 
 # On Unix flavors we need the pthread library
 # On Unix flavors we need the pthread library
-if (NOT ("${CMAKE_SYSTEM_NAME}" STREQUAL "Windows"))
+if (NOT ("${CMAKE_SYSTEM_NAME}" STREQUAL "Windows") AND NOT EMSCRIPTEN)
 	target_compile_options(Jolt PUBLIC -pthread)
 	target_compile_options(Jolt PUBLIC -pthread)
 endif()
 endif()
 
 

+ 1 - 6
UnitTests/Core/JobSystemTest.cpp

@@ -12,12 +12,7 @@ TEST_SUITE("JobSystemTest")
 		// Create job system
 		// Create job system
 		const int cMaxJobs = 128;
 		const int cMaxJobs = 128;
 		const int cMaxBarriers = 10;
 		const int cMaxBarriers = 10;
-		#ifdef JPH_CPU_WASM
-			// At the moment, the WASM unit tests fail when using multiple threads because the thread pool is not working
-			const int cMaxThreads = 0;
-		#else
-			const int cMaxThreads = 10;
-		#endif
+		const int cMaxThreads = 10;
 		JobSystemThreadPool system(cMaxJobs, cMaxBarriers, cMaxThreads);
 		JobSystemThreadPool system(cMaxJobs, cMaxBarriers, cMaxThreads);
 
 
 		// Create array of zeros
 		// Create array of zeros

+ 0 - 5
UnitTests/PhysicsTestContext.cpp

@@ -20,12 +20,7 @@ PhysicsTestContext::PhysicsTestContext(float inDeltaTime, int inCollisionSteps,
 #else
 #else
 	mTempAllocator(new TempAllocatorImpl(4 * 1024 * 1024)),
 	mTempAllocator(new TempAllocatorImpl(4 * 1024 * 1024)),
 #endif
 #endif
-#ifdef JPH_CPU_WASM
-	// At the moment, the WASM unit tests fail when using multiple threads because the thread pool is not working
-	mJobSystem(new JobSystemThreadPool(cMaxPhysicsJobs, cMaxPhysicsBarriers, 0)),
-#else
 	mJobSystem(new JobSystemThreadPool(cMaxPhysicsJobs, cMaxPhysicsBarriers, inWorkerThreads)),
 	mJobSystem(new JobSystemThreadPool(cMaxPhysicsJobs, cMaxPhysicsBarriers, inWorkerThreads)),
-#endif
 	mDeltaTime(inDeltaTime),
 	mDeltaTime(inDeltaTime),
 	mCollisionSteps(inCollisionSteps)
 	mCollisionSteps(inCollisionSteps)
 {
 {