🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

Autowrapping Functions without Native Function Calling on Android (64 bit)

Started by
4 comments, last by WitchLord 2 years, 9 months ago

Currently there is no support for native function calling for android on 64 bit platforms and I do not know enough assembly to even attempt trying to create a set of assembly calls myself. I've used the autowrapper provided in the addons of the sdk however I'm running into a bit of trouble.

The app runs fine on MSVC in both AS_MAX_PORTABILITY mode and using the native calling convention. However when I bring it to Android the native convention obviously doesn't work. I've wrapped my functions using this little ifdef.

#ifdef AS_MAX_PORTABILITY
	#define pFUNCTION(f) WRAP_FN(f)
	#define pFUNCTIONPR(f, p, r) WRAP_FN_PR(f, p, r)
	#define pMETHOD(c, f) WRAP_MFN(c, f)
	#define pMETHODPR(c, f, p, r) WRAP_MFN_PR(c, f, p, r)
	#define pFUNCTION_OL_PR(f, p, r) WRAP_OBJ_LAST_PR(f, p, r)
	#define pCALL_CDECL_OBJLAST asCALL_GENERIC
	#define pCALL_CDECL asCALL_GENERIC
	#define pCALL_THISCALL asCALL_GENERIC
#else
	#define pFUNCTION(f) asFUNCTION(f)
	#define pFUNCTIONPR(f, p, r) asFUNCTIONPR(f, p, r)
	#define pMETHOD(c, f) asMETHOD(c, f)
	#define pMETHODPR(c, f, p, r) asMETHODPR(c, f, p, r)
	#define pFUNCTION_OL_PR(c, f, p, r) asFUNCTIONPR(c, f, p, r)
	#define pCALL_CDECL_OBJLAST asCALL_CDECL_OBJLAST
	#define pCALL_CDECL asCALL_CDECL
	#define pCALL_THISCALL asCALL_THISCALL
	#define pFUNCTION_OL_PR(name, Parameters, ReturnType) asFUNCTIONPR(name, Parameters, ReturnType)
#endif

Works fine on windows but has a segmentation fault on android. Is there anything that would cause this wrapper to behave differently on android?

P.S. Android.mk doesn't build just due to being compiled on incorrect architecture (file: as_callfunc_arm64_gcc.S) throwing a header guard in there fixes it but its no biggie. Excluding the file works aswell.

#if !defined(__ANDROID__) || (defined(__aarch64__) || defined(__x86_64__))
Advertisement

I've fixed the issue. It turns out the one function I was using to test it was registed incorrectly.

engine.RegisterObjectMethod("Console", "void info(string)", pMETHODPR(Console, info, (const std::string&), void), pCALL_THISCALL);

The function should have been registered as a reference &in.

engine.RegisterObjectMethod("Console", "void info(const string &in)", pMETHODPR(Console, info, (const std::string&), void), pCALL_THISCALL);

This just throws a angelscript exception on MSVC but SEGFAULT on android.

This function was called with the native calling convention MSVC and worked fine, so I didn't pick up because it behaved as expected.

Have you tried the latest WIP version?

http://www.angelcode.com/angelscript/wip.php

I merged a patch I received to add support for native calling conventions on Arm64 just a couple of weeks ago.

AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

@WitchLord

Fantastic thank you, runs fine with native calling convention now. I was using the WIP version but I must have downloaded it just a few days before it was updated.

It still doesn't build without this around it:

#if !defined(__ANDROID__) || (defined(__aarch64__) || defined(__x86_64__))

Only when it attempts to build on the 32 bit version. It may be because I'm using an older NDK, but its only a few versions out.

Thanks. I'll add the check for target platform to the file.

AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

This topic is closed to new replies.

Advertisement