[Solved] Access Violation crash with precompiled Jolt Physics .lib in Defold Native Extension

Hi everyone, I’m working on integrating Jolt Physics into a Defold project on Windows.

The Issue:
I have a working version where I include Jolt source files directly in my extension (in src/), and it works perfectly. However, when I try to switch to a precompiled Jolt.lib, I get an Access Violation crash at JPH::BodyManager::AllocateBody immediately upon calling CreateAndAddBody during the extension initialization.

Build Configuration:
I’ve ensured that the Runtime Library matches (using /MT via DUSE_STATIC_MSVC_RUNTIME_LIBRARY=ON). I am using the following CMake flags to build the library:

cmake -G "Visual Studio 18 2026" -A x64 -S Build -B dist ^
  -DCMAKE_INSTALL_PREFIX="C:/libs/jolt-5.5.0-release-msvc" ^
  -DCMAKE_CXX_FLAGS="-DJPH_DEBUG_RENDERER" ^
  -DTARGET_SAMPLES=OFF ^
  -DTARGET_UNIT_TESTS=OFF ^
  -DUSE_STATIC_MSVC_RUNTIME_LIBRARY=ON ^
  -DCPP_EXCEPTIONS_ENABLED=OFF ^
  -DCPP_RTTI_ENABLED=ON ^
  -DOVERRIDE_CXX_FLAGS=ON ^
  -DINTERPROCEDURAL_OPTIMIZATION=OFF
cmake --build dist --config Release --target install

What I’ve verified:

  1. RTTI is enabled in both the Jolt build and my extension code.
  2. The PhysicsSystem is initialized before creating bodies.
  3. The crash occurs regardless of RTTI settings.

Question:
Could this be an ABI mismatch related to virtual interface implementation (e.g., BroadPhaseLayerInterface) when moving from source-included to precompiled .lib? Has anyone encountered similar issues with Jolt virtual interface alignment in Defold/Windows?

Any advice on which additional flags or build configurations I should check would be appreciated!

Here is the call stack: Defold crash with Jolt.lib · GitHub

I have solved this problem by configuring Jolt Physic with the following options. So, download the Jolt Physics source code. Open PowerShell in the source folder. Copy/paste the following command to PowerShell:

cmake -G "Visual Studio 18 2026" -A x64 -S Build -B dist ^
-DCMAKE_INSTALL_PREFIX="C:/libs/jolt-5.5.0-release-msvc" ^
-DTARGET_SAMPLES=OFF ^
-DTARGET_UNIT_TESTS=OFF ^
-DUSE_STATIC_MSVC_RUNTIME_LIBRARY=OFF ^
-DCPP_EXCEPTIONS_ENABLED=ON ^
-DCPP_RTTI_ENABLED=OFF ^
-DOVERRIDE_CXX_FLAGS=ON ^
-DINTERPROCEDURAL_OPTIMIZATION=OFF ^
-DFLOATING_POINT_EXCEPTIONS_ENABLED=OFF ^
-DCMAKE_CXX_FLAGS="/DJPH_DEBUG_RENDERER /DJPH_ENABLE_ASSERTS=1 /DJPH_PROFILE_ENABLED=0 /DJPH_OBJECT_STREAM=1 /MD"

When the configuration above is finished run this command to build and install Jolt Physics:

cmake --build dist --config Release --target install

I’ve attached a simple project. You should install `Jolt Physics` using the commands above. Next, open the my_extension/link_libs.bat and edit the path to yours:

:: link_libs.bat

:: First, remove old folders/links if any remain from previous attempts
rmdir /S /Q include
rmdir /S /Q lib\x86_64-win32

:: Create the folder structure
mkdir lib\x86_64-win32

:: Create symbolic links
:: This line turns the entire include folder into a mirror of the Jolt folder
mklink /D include "C:\libs\jolt-5.5.0-release-msvc\include"

:: This line creates a link to the library file itself
mklink lib\x86_64-win32\Jolt.lib "C:\libs\jolt-5.5.0-release-msvc\lib\Jolt.lib"

Save “link_libs.bat” after editing. Run this file by double click. The “include” and “lib” symbol links will be generated. After this you can run the example.

JoltLineDebugRendererInDefold_FloorAndCube.zip (9.7 KB)

It draws AABB:

1 Like