Premature destruction of object in Android

Started by
34 comments, last by AgentC 11 years, 1 month ago

OK. Well, at least we've narrowed down the problem to the templates and there is a work around. I still have to reproduce this problem so I can find the problem in the templates. I may ask you for some help in that later on as I get a chance to really sit down and work on this.

Rather than manually implementing all the generic wrapper functions (at least until I can have the autowrappers, or the native calling conventions working) you may want to try the previous version of the autowrappers. That implementation was slightly less complex and may thus work better.

The app shouldn't crash when the script attempts to call a method on a null handle. The context should raise a script exception in this situation which will make Execute() return with the return code asEXECUTION_EXCEPTION. You'll need to handle this return code, and you'll probably want to log some info about it (See helper add-on function PrintException() for tips on how to do that). Are you handling the return code from Execute(), or is the crash happening before Execute() returns?

And about the native calling conventions on ARM. Can you find out which defines that are provided by default in the compiler, so I can see if the as_config.h is correct? I'm not sure what compiler you use, but with gnuc, you can get this list with the following command: echo . | g++ -dM -E -

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

Advertisement

So, two ot of three issues solved, thanks!

About the ARM now, here is the compilation command of one source file from angelscript, compiling the ARM version for the NDK.


"Compile++ thumb : angelscript <= as_scriptengine.cpp
K:/NDK8/toolchains/arm-linux-androideabi-4.6/prebuilt/windows/bin/arm-linux-androideabi-g++ -MMD -MP -MF ./obj/local/armeabi/objs/angelscript/as_scriptengine.o.d -fpic -ffunction-sections -funwind-tables -fstack-protector -D__ARM_ARCH_5__ -D__ARM_ARCH_5T__ -D__ARM_ARCH_5E__ -D__ARM_ARCH_5TE__ -no-canonical-prefixes -march=armv5te -mtune=xscale -msoft-float -fexceptions -fno-rtti -mthumb -Os -g -DNDEBUG -fomit-frame-pointer -fno-strict-aliasing -finline-limit=64 -IK:/NDK8/sources/cxx-stl/system/include -Ijni/../../../source -DANDROID  -Wa,--noexecstack      -IK:/NDK8/platforms/android-9/arch-arm/usr/include -c  jni/../../../source/as_scriptengine.cpp -o ./obj/local/armeabi/objs/angelscript/as_scriptengine.o 
 

About the defines:


#define __DBL_MIN_EXP__ (-1021)
#define __UINT_LEAST16_MAX__ 65535
#define __FLT_MIN__ 1.1754943508222875e-38F
#define __UINT_LEAST8_TYPE__ unsigned char
#define __INTMAX_C(c) c ## LL
#define __CHAR_BIT__ 8
#define __UINT8_MAX__ 255
#define __ANDROID__ 1
#define __WINT_MAX__ 4294967295U
#define __ORDER_LITTLE_ENDIAN__ 1234
#define __SIZE_MAX__ 4294967295U
#define __WCHAR_MAX__ 4294967295U
#define __DBL_DENORM_MIN__ ((double)4.9406564584124654e-324L)
#define __FLT_EVAL_METHOD__ 0
#define __unix__ 1
#define __UINT_FAST64_MAX__ 18446744073709551615ULL
#define __SIG_ATOMIC_TYPE__ int
#define __DBL_MIN_10_EXP__ (-307)
#define __FINITE_MATH_ONLY__ 0
#define __ARMEL__ 1
#define __GNUC_PATCHLEVEL__ 0
#define __UINT_FAST8_MAX__ 255
#define __DEC64_MAX_EXP__ 385
#define __INT8_C(c) c
#define __UINT_LEAST64_MAX__ 18446744073709551615ULL
#define __SHRT_MAX__ 32767
#define __LDBL_MAX__ 1.7976931348623157e+308L
#define __ARM_ARCH_5TE__ 1
#define __UINT_LEAST8_MAX__ 255
#define __GXX_TYPEINFO_EQUALITY_INLINE 0
#define __UINTMAX_TYPE__ long long unsigned int
#define __linux 1
#define __DEC32_EPSILON__ 1E-6DF
#define __CHAR_UNSIGNED__ 1
#define __UINT32_MAX__ 4294967295U
#define __LDBL_MAX_EXP__ 1024
#define __WINT_MIN__ 0U
#define __linux__ 1
#define __SCHAR_MAX__ 127
#define __WCHAR_MIN__ 0U
#define __INT64_C(c) c ## LL
#define __DBL_DIG__ 15
#define __SIZEOF_INT__ 4
#define __SIZEOF_POINTER__ 4
#define __USER_LABEL_PREFIX__ 
#define __STDC_HOSTED__ 1
#define __LDBL_HAS_INFINITY__ 1
#define __FLT_EPSILON__ 1.1920928955078125e-7F
#define __APCS_32__ 1
#define __LDBL_MIN__ 2.2250738585072014e-308L
#define __DEC32_MAX__ 9.999999E96DF
#define __INT32_MAX__ 2147483647
#define __SIZEOF_LONG__ 4
#define __UINT16_C(c) c
#define __DECIMAL_DIG__ 17
#define __LDBL_HAS_QUIET_NAN__ 1
#define __GNUC__ 4
#define __FLT_HAS_DENORM__ 1
#define __SIZEOF_LONG_DOUBLE__ 8
#define __BIGGEST_ALIGNMENT__ 8
#define __DBL_MAX__ ((double)1.7976931348623157e+308L)
#define __INT_FAST32_MAX__ 2147483647
#define __DBL_HAS_INFINITY__ 1
#define __DEC32_MIN_EXP__ (-94)
#define __THUMB_INTERWORK__ 1
#define __INT_FAST16_TYPE__ int
#define __LDBL_HAS_DENORM__ 1
#define __DEC128_MAX__ 9.999999999999999999999999999999999E6144DL
#define __INT_LEAST32_MAX__ 2147483647
#define __ARM_PCS 1
#define __DEC32_MIN__ 1E-95DF
#define __DBL_MAX_EXP__ 1024
#define __DEC128_EPSILON__ 1E-33DL
#define __PTRDIFF_MAX__ 2147483647
#define __LONG_LONG_MAX__ 9223372036854775807LL
#define __SIZEOF_SIZE_T__ 4
#define __SIZEOF_WINT_T__ 4
#define __GXX_ABI_VERSION 1002
#define __SOFTFP__ 1
#define __FLT_MIN_EXP__ (-125)
#define __INT_FAST64_TYPE__ long long int
#define __DBL_MIN__ ((double)2.2250738585072014e-308L)
#define __DEC128_MIN__ 1E-6143DL
#define __REGISTER_PREFIX__ 
#define __UINT16_MAX__ 65535
#define __DBL_HAS_DENORM__ 1
#define __UINT8_TYPE__ unsigned char
#define __NO_INLINE__ 1
#define __FLT_MANT_DIG__ 24
#define __VERSION__ "4.6 20120106 (prerelease)"
#define __UINT64_C(c) c ## ULL
#define __FLOAT_WORD_ORDER__ __ORDER_LITTLE_ENDIAN__
#define __INT32_C(c) c
#define __DEC64_EPSILON__ 1E-15DD
#define __ORDER_PDP_ENDIAN__ 3412
#define __DEC128_MIN_EXP__ (-6142)
#define __INT_FAST32_TYPE__ int
#define __UINT_LEAST16_TYPE__ short unsigned int
#define unix 1
#define __INT16_MAX__ 32767
#define __SIZE_TYPE__ unsigned int
#define __UINT64_MAX__ 18446744073709551615ULL
#define __INT8_TYPE__ signed char
#define __ELF__ 1
#define __FLT_RADIX__ 2
#define __INT_LEAST16_TYPE__ short int
#define __LDBL_EPSILON__ 2.2204460492503131e-16L
#define __UINTMAX_C(c) c ## ULL
#define __SIG_ATOMIC_MAX__ 2147483647
#define __VFP_FP__ 1
#define __SIZEOF_PTRDIFF_T__ 4
#define __DEC32_SUBNORMAL_MIN__ 0.000001E-95DF
#define __INT_FAST16_MAX__ 2147483647
#define __UINT_FAST32_MAX__ 4294967295U
#define __UINT_LEAST64_TYPE__ long long unsigned int
#define __FLT_HAS_QUIET_NAN__ 1
#define __FLT_MAX_10_EXP__ 38
#define __LONG_MAX__ 2147483647L
#define __DEC128_SUBNORMAL_MIN__ 0.000000000000000000000000000000001E-6143DL
#define __FLT_HAS_INFINITY__ 1
#define __unix 1
#define __UINT_FAST16_TYPE__ unsigned int
#define __DEC64_MAX__ 9.999999999999999E384DD
#define __CHAR16_TYPE__ short unsigned int
#define __PRAGMA_REDEFINE_EXTNAME 1
#define __INT_LEAST16_MAX__ 32767
#define __DEC64_MANT_DIG__ 16
#define __INT64_MAX__ 9223372036854775807LL
#define __UINT_LEAST32_MAX__ 4294967295U
#define __INT_LEAST64_TYPE__ long long int
#define __INT16_TYPE__ short int
#define __INT_LEAST8_TYPE__ signed char
#define __DEC32_MAX_EXP__ 97
#define __INT_FAST8_MAX__ 127
#define __INTPTR_MAX__ 2147483647
#define linux 1
#define __LDBL_MANT_DIG__ 53
#define __DBL_HAS_QUIET_NAN__ 1
#define __SIG_ATOMIC_MIN__ (-__SIG_ATOMIC_MAX__ - 1)
#define __INTPTR_TYPE__ int
#define __UINT16_TYPE__ short unsigned int
#define __WCHAR_TYPE__ unsigned int
#define __SIZEOF_FLOAT__ 4
#define __pic__ 1
#define __UINTPTR_MAX__ 4294967295U
#define __DEC64_MIN_EXP__ (-382)
#define __INT_FAST64_MAX__ 9223372036854775807LL
#define __FLT_DIG__ 6
#define __UINT_FAST64_TYPE__ long long unsigned int
#define __INT_MAX__ 2147483647
#define __INT64_TYPE__ long long int
#define __FLT_MAX_EXP__ 128
#define __DBL_MANT_DIG__ 53
#define __INT_LEAST64_MAX__ 9223372036854775807LL
#define __DEC64_MIN__ 1E-383DD
#define __WINT_TYPE__ unsigned int
#define __UINT_LEAST32_TYPE__ unsigned int
#define __SIZEOF_SHORT__ 2
#define __LDBL_MIN_EXP__ (-1021)
#define __arm__ 1
#define __INT_LEAST8_MAX__ 127
#define __LDBL_MAX_10_EXP__ 308
#define __DBL_EPSILON__ ((double)2.2204460492503131e-16L)
#define __UINT8_C(c) c
#define __INT_LEAST32_TYPE__ int
#define __SIZEOF_WCHAR_T__ 4
#define __UINT64_TYPE__ long long unsigned int
#define __INT_FAST8_TYPE__ signed char
#define __DBL_DECIMAL_DIG__ 17
#define __DEC_EVAL_METHOD__ 2
#define __ORDER_BIG_ENDIAN__ 4321
#define __UINT32_C(c) c ## U
#define __INTMAX_MAX__ 9223372036854775807LL
#define __BYTE_ORDER__ __ORDER_LITTLE_ENDIAN__
#define __FLT_DENORM_MIN__ 1.4012984643248171e-45F
#define __INT8_MAX__ 127
#define __PIC__ 1
#define __UINT_FAST32_TYPE__ unsigned int
#define __CHAR32_TYPE__ unsigned int
#define __FLT_MAX__ 3.4028234663852886e+38F
#define __INT32_TYPE__ int
#define __SIZEOF_DOUBLE__ 8
#define __FLT_MIN_10_EXP__ (-37)
#define __INTMAX_TYPE__ long long int
#define __DEC128_MAX_EXP__ 6145
#define __GNUC_MINOR__ 6
#define __UINTMAX_MAX__ 18446744073709551615ULL
#define __DEC32_MANT_DIG__ 7
#define __DBL_MAX_10_EXP__ 308
#define __LDBL_DENORM_MIN__ 4.9406564584124654e-324L
#define __INT16_C(c) c
#define __STDC__ 1
#define __PTRDIFF_TYPE__ int
#define __UINT32_TYPE__ unsigned int
#define __UINTPTR_TYPE__ unsigned int
#define __DEC64_SUBNORMAL_MIN__ 0.000000000000001E-383DD
#define __ARM_EABI__ 1
#define __DEC128_MANT_DIG__ 34
#define __LDBL_MIN_10_EXP__ (-307)
#define __SIZEOF_LONG_LONG__ 8
#define __LDBL_DIG__ 15
#define __FLT_DECIMAL_DIG__ 9
#define __UINT_FAST16_MAX__ 4294967295U
#define __GNUC_GNU_INLINE__ 1
#define __UINT_FAST8_TYPE__ unsigned char
#define __ARM_FEATURE_DSP 1
 

Hope it helps..

I see that the defines include both __ANDROID__ and __linux__. This is probably what's causing the problems you're seeing. With the latest release I added support for native calling conventions on Linux with arm. I wasn't aware that the define __linux__ was present on Android too, so now the code in as_callfunc_arm.cpp and as_callfunc_arm_gcc.S is mostly likely compiled incorrectly.

I'll review the defines that I use in as_config.h, as_callfunc_arm.cpp and as_callfunc_arm_gcc.S to have this fixed.

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

The native calling conventions should be working again on Android with revision 1586.

I wasn't able to reproduce the problem with the autowrappers. Perhaps it is something compiler specific. What compiler did you use when you reproduced the problem on Windows?

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

I recompiled the ARM version from the new revision and it doesn't seem to be working. Now it seems less like a crash and more like a sudden process halt down without even logging the stack frame.

I think I didn't do anything wrong..


void testP()
{
TESTLOG("EIUGBIAUSBGFUIASBGFAUSBGOUIASBGOIASBGOASBNG")
}
r = asEngine->RegisterGlobalFunction("void testP()", asFUNCTION(testP), asCALL_CDECL);

 

How big is the improvement switching from generics to ARM instructions?

I am compiling for android with the latest NDK and for windows with visual studio 2010, the default compiler..

then from the script, calling testP() results in process death.

Does angelscript need RTTI? dynamic_cast anywhere?

Would it be possible for you to debug the code to see exactly where it fails inside the library when running on Android?

Did you use the earlier version of AngelScript from 2012 on Android? Or is this the first time you started using it on Android?

I can't say how big the improvement will be with using native calling conventions. I can't even say there will be an improvement, as it is quite likely the setup that has to be done in as_callfunc_arm.cpp give a higher overhead than the generic calling convention do.

AngelScript doesn't rely on RTTI. There are no dynamic_casts in the code.

I'll see if I can reproduce the problem with the autowrappers on msvc2010. I'm currently running using msvc2012, but I have 2010 on another machine.

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

Not even with msvc2010 could I reproduce the problem with the autowrappers. There is probably something very specific about the classes you have that triggers the problem in the templates.

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

I would love to debug the code to see what is wrong, but to be honest, debugging in android is far from ideal. Most people say it sucks beyond sanity and well, it seems to be true..

I am kind of weaponless when it comes to debugging in android, I am not sure what to do, but I will gladly follow your tips if you have any. In the meanwhile I will google a bit..

About the angelscript library, I used the previous one on android and ios and windows and everywhere else and all worked fine.. The only thing that is first time is aiming for ARM code by removing AS_MAX_PORTABILITY flag.

Thanks for all the other answers! I will give feedback about the bug if I come into more information. And for now I will keep the work going with generic calls..

EDIT: Yes, this problem seems to be specific to my case. I know for a fact it happened with UIButton, but I didnt even come to test other types I had registered..

Which version of AngelScript did you use before on Android? Maybe I can spot the problem by comparing the code of the two versions.

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

It was 2.23.0 .

It worked then, and the bug was introduced when i swapped to the latest one. (The upgrade was really smooth, no changes needed anywhere, just added PushState and PopState to all calls)

EDIT: Im sorry, I tried my best for the debugging part and I could not get anywhere.. I learned how to know which line and function crashed the program and that works fine for other crashes and is actually helpful. However, for the crash dump from the unfixed latest version, it is not able to locate any useful info and with the patched version you gave me today no crash dump is even generated, just a immediate death of the program.

I really have no idea how to be helpful debugging this, my best bet on whats crashing is the assembly code for ARM (because it cant probably locate debug info for that) but I have no idea..

Noone got this working before me? Strange..

This topic is closed to new replies.

Advertisement