Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MSVC][x86] Compile error in box2d\src\core.c and box2d\samples\main.cpp #815

Closed
NEIL-smtg opened this issue Oct 3, 2024 · 1 comment
Closed

Comments

@NEIL-smtg
Copy link

Hi, I work on MSVC compiler testing, and we regularly build popular open-source project including box2d, with development builds of MSVC in order to find and fix regressions before they ship and cause problems for you.

Recently, as I build box2d with x86 as the target architecture from source with MSVC, I encountered the error as following:

C:\gitP\erincatto\box2d\src\core.c(118,8): error C2220: the following warning is treated as an error [C:\gitP\erincatto\box2d\build_x86\src\box2d.vcxproj]
C:\gitP\erincatto\box2d\src\core.c(118,8): warning C4047: 'initializing': 'void *' differs in levels of indirection from 'int' [C:\gitP\erincatto\box2d\build_x86\src\box2d.vcxproj]

I have encountered this error at https://github.com/erincatto/box2d/blob/main/src/core.c#L118 and https://github.com/erincatto/box2d/blob/main/samples/main.cpp#L74.

#ifdef B2_PLATFORM_WINDOWS
	void* ptr = _aligned_malloc( size32, B2_ALIGNMENT );
#elif defined( B2_PLATFORM_ANDROID )
    ....
#else
	void* ptr = aligned_alloc( B2_ALIGNMENT, size32 ); // error c2220
#endif

The compiler somehow is entering into the else block, but MSVC does not supporting aligned_alloc but they have a _aligned_malloc instead. For more details, refer to the official documentation: aligned-malloc.

After I have applied this msvc_suport.patch, the build was successful, but it introduced a new issue when running test.exe. Although the test runs successfully, the exit code is incorrect. This suggests that the patch I used is likely not the correct solution."

image

Steps to reproduce:

  1. Open x86 native tools command prompt for vs2022
  2. git clone https://github.com/erincatto/box2d.git
  3. cd erincatto/box2d
  4. mkdir build_x86
  5. cd build_x86
  6. set VSCMD_SKIP_SENDTELEMETRY=1 & "C:\Program Files\Microsoft Visual Studio\2022\Enterprise\Common7\Tools\VsDevCmd.bat" -host_arch=x86 -arch=x86
  7. cmake -G "Visual Studio 17 2022" -A Win32 -DCMAKE_SYSTEM_VERSION=10.0.22621.0 .. 2>&1
  8. msbuild /m /p:Platform=Win32 /p:Configuration=Release box2d.sln /t:Rebuild 2>&1
  9. .\bin\Release\test.exe 2>&1

Build log: box2d.log

erincatto added a commit that referenced this issue Oct 6, 2024
erincatto added a commit that referenced this issue Oct 6, 2024
- optimized ray and shape cast : 2x faster
- update mass options instead of automatic mass
- fixes for 32-bit Windows build
- b2TreeStats for measuring query performance
- reduced tree node size from 48-bytes to 40-bytes
- fixes for 32-bit Neon
- MSVC warning level 4 and fixes
#814, #815, #813, #809
@erincatto
Copy link
Owner

Fixed some 32-bit x86 issues in #817. You should not need any Windows patches.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants