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

Android compilation issues #782

Closed
eduardodoria opened this issue Aug 28, 2024 · 3 comments
Closed

Android compilation issues #782

eduardodoria opened this issue Aug 28, 2024 · 3 comments

Comments

@eduardodoria
Copy link

I had to modify some parts to build for Android.

In file allocate.c the function aligned_alloc is only supported starting from Android API level 28, so I'm using posix_memalign instead:

#if defined(B2_PLATFORM_WINDOWS)
    void* ptr = _aligned_malloc( size32, B2_ALIGNMENT );
#elif defined(B2_PLATFORM_ANDROID)
    void* ptr = NULL;
    if (posix_memalign(&ptr, B2_ALIGNMENT, size32) != 0) {
        ptr = NULL;  // Allocation failed
    }
#else
    void* ptr = aligned_alloc( B2_ALIGNMENT, size32 );
#endif

In file core.h I modified this part to compile for x86 and arm (maybe need to rename B2_CPU_X64 macro):

// Define CPU
#if defined( __x86_64__ ) || defined( _M_X64 )
#define B2_CPU_X64
#elif defined( __i386__ ) || defined( _M_IX86 )
#define B2_CPU_X64
#elif defined( __aarch64__ ) || defined( _M_ARM64 )
#define B2_CPU_ARM
#elif defined( __arm__ ) || defined( _M_ARM )
#define B2_CPU_ARM
#elif defined( __EMSCRIPTEN__ )
#define B2_CPU_WASM
#else
#error Unsupported CPU
#endif

At same core.h file I needed to add B2_BREAKPOINT macro to Android:

#if defined( B2_COMPILER_MSVC )
#define B2_BREAKPOINT __debugbreak()
[...]
#elif defined( B2_PLATFORM_ANDROID )
#define B2_BREAKPOINT __builtin_trap()
[...]
#else
#error Unknown platform
#endif
@erincatto
Copy link
Owner

Thanks for the write up.

Shouldn't the application exit if it is out of memory?

Isn't the break point a property of the compiler?

@eduardodoria
Copy link
Author

These modifications I did is working.

I've got many errors before:

allocate.c:71:14: error: call to undeclared library function 'aligned_alloc' with type 'void *(unsigned long, unsigned long)'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
          void* ptr = aligned_alloc( B2_ALIGNMENT, size32 )

After that I got "Unsupported CPU" error.

And after that, B2_BREAKPOINT is not defined.

I have not tested the possible implications that these changes may cause. But in my engine I updated to the Box2D "main" version (I also had more errors with 3.0.0 ) and needed to make these changes quickly.

You can look my workflow from Android:
https://github.com/supernovaengine/supernova/actions/runs/10624088233/job/29451747819

erincatto added a commit that referenced this issue Aug 31, 2024
@erincatto erincatto mentioned this issue Aug 31, 2024
erincatto added a commit that referenced this issue Aug 31, 2024
- renamed smooth segment to chain segment
- addressed several minor issues

#777
#779
#754 
#749 
#782 
#781 
#776
@erincatto
Copy link
Owner

Fixed in #783

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