Jump to content

  • Log In with Google      Sign In   
  • Create Account

FREE SOFTWARE GIVEAWAY

We have 4 x Pro Licences (valued at $59 each) for 2d modular animation software Spriter to give away in this Thursday's GDNet Direct email newsletter.


Read more in this forum topic or make sure you're signed up (from the right-hand sidebar on the homepage) and read Thursday's newsletter to get in the running!


- - - - -

Marmalade: Angelscript runs fine on x86, crashes on ARM


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
35 replies to this topic

#1 UltimateWalrus   Members   -  Reputation: 197

Like
1Likes
Like

Posted 24 September 2012 - 10:45 AM

Hello,

I am making a mobile game engine that runs on TinyXML and Angelscript. I'm using MSVC 2010 Professional. I used the Marmalade Angelscript project found in this thread and it seems to be working. So far, I've made it so I can define hierarchical game objects and their properties in XML, and optionally reference Angelscript scripts that specialize the functionality even further. Angelscript looks very promising, and while there've been a few hiccups I couldn't find reference to in the documentation, the library seems to be designed sensibly enough that with enough persistence I can usually figure out what's wrong.

Now, however, I'm completely stuck. I suspect the issue may lie with Marmalade as much as Angelscript. The engine runs flawlessly when I compile to x86 and run it in the Marmalade simulator. However, when I want to compile to ARM so I can run on an iOS device, something bad happens and it crashes. I stepped through in the ARM simulator and found the game was blowing up whenever I tried to register a function for Angelscript. Upon further inspection, I saw the AS_MAX_PORTABILITY #define was getting set, making it so I can only use the "generic" calling convention. I haven't written a lot of cross-platform code so I'm a newbie to thinking about different calling conventions, but from searching it looks to me as if ARM is supposed to be able to use CDECL function calls just fine.

Using #pragma messages I figured out where AS_MAX_PORTABILITY was getting defined. It's here in as_config.h:
#if (!defined(AS_X86) && !defined(AS_SH4) && !defined(AS_MIPS) && !defined(AS_PPC) && !defined(AS_PPC_64) && !defined(AS_XENON) && !defined(AS_X64_GCC) && !defined(AS_X64_MSVC) && !defined(AS_ARM) && !defined(AS_X64_MINGW))
#ifndef AS_MAX_PORTABILITY
  #define AS_MAX_PORTABILITY
#endif
#endif

AS_MARMALADE is defined, but I realized that AS_ARM should probably also be defined, so I tried setting that in the project properties. Unfortunately when I do that, along with some probably-harmless warnings about ignoring stdcall, I get compiler errors:

1>  Debug_AngelScript_new_vc10_gcc_arm/as_callfunc_arm.obj: In function `CallSystemFunctionNative(asCContext*, asCScriptFunction*, void*, unsigned long*, void*, unsigned long long&)':
1> 
1> 
1>  d:/sebastian/games/marmalade/angelscript_new3/angelscript_marmalade/angelscript/source/as_callfunc_arm.cpp(126) : undefined reference to `armFuncR0'
1> 
1> 
1>  d:/sebastian/games/marmalade/angelscript_new3/angelscript_marmalade/angelscript/source/as_callfunc_arm.cpp(130) : undefined reference to `armFunc'
1> 
1> 
1>  d:/sebastian/games/marmalade/angelscript_new3/angelscript_marmalade/angelscript/source/as_callfunc_arm.cpp(134) : undefined reference to `armFuncR0'
1> 
1> 
1>  d:/sebastian/games/marmalade/angelscript_new3/angelscript_marmalade/angelscript/source/as_callfunc_arm.cpp(142) : undefined reference to `armFuncR0R1'
1> 
1> 
1>  d:/sebastian/games/marmalade/angelscript_new3/angelscript_marmalade/angelscript/source/as_callfunc_arm.cpp(147) : undefined reference to `armFuncR0'
1> 
1> 
1>  d:/sebastian/games/marmalade/angelscript_new3/angelscript_marmalade/angelscript/source/as_callfunc_arm.cpp(155) : undefined reference to `armFuncR0R1'
1> 
1> 
1>  d:/sebastian/games/marmalade/angelscript_new3/angelscript_marmalade/angelscript/source/as_callfunc_arm.cpp(159) : undefined reference to `armFuncObjLast'
1> 
1> 
1>  d:/sebastian/games/marmalade/angelscript_new3/angelscript_marmalade/angelscript/source/as_callfunc_arm.cpp(162) : undefined reference to `armFuncR0ObjLast'

This doesn't make any sense, since the extern function definitions appear to be right there at the top of the document. I get that they reference assembler routines, but if anything went wrong there I would expect a linker error not a compiler error. I've fiddled around with as_config.h a little more but can't find the solution.

I feel like I'm stuck, since going any further would require fiddling around with the Angelscript source, in a place where I don't really fully understand how it works. Are there any ideas of what I can do to get Angelscript to run correctly when built for ARM? I am doing this game as part of a small sponsorship deal so I am on a really tight schedule. Worst case scenario, I can kludge this milestone by "pretending" Angelscript is being used; however it looks as though Andreas Jönsson peruses these forums somewhat frequently so I thought posting would be a good idea. I feel a little guilty asking for quick help from the creator of a library that's already very graciously offered for free... You have my word that, if the game makes any money, I'll be sure to make a nice donation on the AngelCode site :]

Thank you very much,
Sebastian

Sponsor:

#2 Andreas Jonsson   Moderators   -  Reputation: 3452

Like
0Likes
Like

Posted 03 October 2012 - 07:26 PM

From our conversation via e-mail I know you have a work around already with the use of generic calling conventions and the auto wrapper add-on. However, now that I'm back from my vacation I'll start looking into this.
AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

#3 Andreas Jonsson   Moderators   -  Reputation: 3452

Like
2Likes
Like

Posted 21 October 2012 - 10:56 AM

The biggest problem with Marmalade is that it appears to remove all predefines that are normally available. This makes the code in as_config.h fail to identify the target platform and thus doesn't properly set up the defines that the rest of the code need to compile properly.

When compiling for the ARM platform, you need to make sure the macro _ARM_ is defined globally. This should make as_config.h set up the proper macros for ARM, including AS_ARM define.

You will also have to include the as_callfunc_arm_msvc.asm in the project, so the armFuncXXX functions get compiled too. I'm not sure how Marmalade will handle the assembler code. However, as Marmalade can use MSVC10, it can probably also use custom build commands. For the assembler file you can probably use the following custom build command:

armasm -g $(InputPath)


Add to this the recommendations from our e-mail conversations:

1) Defined AS_NO_THREADS to avoid the problem with pthread_rwlock_t
2) Change angelscript.h to use typedef size_t asPWORD; instead of typedef uintptr_t asPWORD;


I'd very much like to see Marmalade working with native calling conventions too. Let me know if the above changes work, and I'll make them part of the official code.


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

#4 UltimateWalrus   Members   -  Reputation: 197

Like
0Likes
Like

Posted 22 October 2012 - 12:16 AM

Hi Andreas,

Thank you very much for the help! With your suggestions I managed to get version 2.25.0 compiling. However, when I run on ARM, the crash still persists. The crash seems to be happening when the program returns from asFunctionPtr. At this point Marmalade gives the following error:

IwAssert failure:
Channel: S3E
File: iwcrt_common.cpp
Line: 836
Expression: false
Message: application aborted

Any ideas?

Thanks,
Sebastian

#5 Andreas Jonsson   Moderators   -  Reputation: 3452

Like
1Likes
Like

Posted 22 October 2012 - 07:26 AM

I'm not sure. asFunctionPtr is a template function to copy different function pointers into a common structure that AngelScript can use to determine how to call the application function. The implementation of asFunctionPtr is extremely simple, I don't see how it could fail inside this function.

Can you show the callstack when the assert happens?
AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

#6 UltimateWalrus   Members   -  Reputation: 197

Like
1Likes
Like

Posted 23 October 2012 - 05:34 PM

Unfortunately, with Marmalade I can only debug ARM builds with a somewhat limited debugger, which for some reason can't show me the callstack once the assert has happened. However, I figured it out by more carefully stepping through the code.


It actually wasn't failing inside of asFunctionPtr (the weird debugger was just making it look that way). The cause of the failure appears to be inside of RegisterBehaviourToObjectType, seemingly because AS_MAX_PORTABILITY is getting defined, making it fail when I try to use CDECL. The problem seems to be happening here:
#ifdef AS_MAX_PORTABILITY
   if( callConv != asCALL_GENERIC )
    return ConfigError(asNOT_SUPPORTED, "RegisterObjectBehaviour", objectType->name.AddressOf(), decl);
#endif
The code I have written that makes this happen is essentially this:
  // Create the script script_engine
  script_engine = asCreateScriptEngine(ANGELSCRIPT_VERSION);
  // Set the message callback to receive information on errors in human readable form.
  int r = script_engine->SetMessageCallback(asFUNCTION(MessageCallback), 0, asCALL_CDECL); assert( r >= 0 );
  //Register the Vector2 primitive
  r = engine->RegisterObjectType("Vector2", sizeof(Vector2),
    asOBJ_VALUE | asOBJ_POD | asOBJ_APP_CLASS | asOBJ_APP_CLASS_CONSTRUCTOR | asOBJ_APP_CLASS_ASSIGNMENT | asOBJ_APP_CLASS_COPY_CONSTRUCTOR); assert( r >= 0 );
  r = engine->RegisterObjectBehaviour("Vector2", asBEHAVE_CONSTRUCT, "void f()", asFUNCTION(trVector2Factory1), asCALL_CDECL_OBJFIRST); assert( r >= 0 );

Once RegisterObjectBehaviour returns an error, my assertion fails (would've been nice if Marmalade told me that instead of a cryptic message about iwcrt_common.cpp).

This works fine on x86 as long as I don't have _ARM_ defined. Maybe the problem is that, by defining _ARM_, I've somehow got AS_MAX_PORTABILITY getting defined as well(when it shouldn't be if I want to use CDECL)?

#7 Andreas Jonsson   Moderators   -  Reputation: 3452

Like
1Likes
Like

Posted 23 October 2012 - 05:51 PM

Apparently the as_config.h is not detecting that you're compiling for an ARM processor and automatically turn on AS_MAX_PORTABILITY.

As you're compiling with MSVC the following defines must be given in order for as_config.h to properly detect the target CPU.

_MSC_VER
MARMALADE
_ARM_

Try forcing those defines in the project settings when compiling the AngelScript library.


It would help a lot if there is a way to see what defines are predefined when compiling with Marmalade. This would require a lot less guesswork then.
AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

#8 UltimateWalrus   Members   -  Reputation: 197

Like
0Likes
Like

Posted 23 October 2012 - 09:59 PM

I ran into a couple issues using these defines.

First, thus far I've had to use AS_MARMALADE rather than simply MARMALADE. The add-ons won't compile with just MARMALADE. I thought it might be because they don't include as_config.h, but while adding #include "../../angelscript/source/as_config.h" made Intellisense happy, it still wouldn't compile for some reason. I get errors like this:

error : no matching function for call to 'operator new [](unsigned int, const _STL::nothrow_t&)' d:\sebastian\games\marmalade\elasticocean\angelscripttest2\angelscript_marmalade\add_on\scriptarray\scriptarray.cpp 413 1 AngelScript_new_vc10

It also seems like I can't define _MSC_VER. Doing so causes a ton of compiler errors within Marmalade (too many to list). I dunno if it's helpful but the first error looks like this:

error : there are no arguments to 'IwDebugExit' that depend on a template parameter, so a declaration of 'IwDebugExit' must be available d: ools\game\marmalade\6.0\modules\iwutil\h\IwDebug.h 591 1 AngelScript_new_vc10

If need be I can ask for help in the Marmalade forums, but I need to know what to ask.

#9 Andreas Jonsson   Moderators   -  Reputation: 3452

Like
1Likes
Like

Posted 24 October 2012 - 08:32 AM

You can use AS_MARMALADE instead of MARMALADE.

_MSC_VER really should be defined internally by the MSVC compiler, so defining it manually could definitely cause some troubles. I just asked you to define it because it seemed that it wasn't defined already.

I would really like to know what defines are given automatically by Marmalade when compiling for ARM with the MSVC compiler. If you can ask on the Marmalade forum if anyone knows how to find that out it would be good.

Without it I really don't know why as_config.h doesn't properly identify that the target platform is Marmalade with ARM.

If you look at the as_config.h it is really quite simple:

Line382: #if defined(_MSC_VER) && !defined(__MWERKS__)
Line404: #if defined(AS_MARMALADE) || defined (MARMALADE)
Line452: #ifdef _ARM_

These three conditions should be evaluated to true in order for it to work, but for some reason it doesn't seem to be the case for you.
AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

#10 loboWu   Members   -  Reputation: 201

Like
1Likes
Like

Posted 29 October 2012 - 11:54 PM

Dear Andreas:
I had made marmalade project, and run as native ARM api.
It works on Android and iOS.
Just let you known, and I will be glad to share my experience.

The attached Files are my marmalade mkb.
I think it works for 2.25.1 (2.25.0 need some patch)
Besides, you should remove all comments in as_callfunc_arm_gcc.S

And use scons to build marmalade arm library( just right click on the angelscript_lib.mkb,
and choose "Build and Run ARM GCC release")

marmalade use gcc compiler to build the library, so the ABI is the same as gcc.
I use the gcc ARM native ABI to build marmalade library, and it really run on Adnroid and iOS.
I am so happy that angelscript is almost really platform independent, I compile my bytecode on PC,
and run on Android.

#11 loboWu   Members   -  Reputation: 201

Like
1Likes
Like

Posted 30 October 2012 - 04:19 AM

Here is the attached file

Attached Files



#12 Andreas Jonsson   Moderators   -  Reputation: 3452

Like
0Likes
Like

Posted 30 October 2012 - 06:24 AM

Thanks for sharing this loboWu.

I'm very pleased to know it works properly.

I didn't know Marmalade used gcc to build for ARM. Are you building the library from Windows? Do you have to make a separate download of gcc or does it come with the Marmalade SDK?
AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

#13 loboWu   Members   -  Reputation: 201

Like
0Likes
Like

Posted 31 October 2012 - 03:41 AM

The arm gcc compiler is just come with marmalade SDK.
It use arm-none-eabi with GCC 4.4.1

#14 UltimateWalrus   Members   -  Reputation: 197

Like
0Likes
Like

Posted 01 November 2012 - 05:10 PM

Hi IoboWu,

Thank you for sharing your project files. Could you explain a little bit about how you use them? I downloaded them and, judging from the file paths inside them, assumed I'm supposed to put them in angelscript/projects/marmalade. When I run the *.mkb I get a slew of errors about unrecognized opcodes, concluding with the error:

error: Executing 'd: ools\game\marmalade\6.0\s3e\bin\scons.bat -Q compiler=gcc' failed. (return code 2)

I tried including the path of the *.mkf from my current Marmalade project; when I do this, the project loads, but upon compiling I get:

Error 4 error MSB6006: "link.exe" exited with code 1.

I also tried copying various parts of your *.mkb into the *.mkf I have been using to include Angelscript. Copying most of the stuff over caused no change (the program still fails when I try to register a CDECL function on ARM), but copying the part about the *.S files makes the project fail to load up. In this scenario the command line seems to be actually compiling the code, which is a bit strange... it fails when trying to use an add-on, RegisterStdString, claiming it "was not declared in this scope."

Sorry I'm having so much difficulty figuring this stuff out... I don't have much experience writing multiplatform code or with Marmalade but I've been trying my best. If somewhere there was a complete downloadable Marmalade project that demonstrates compiling and running the latest Angelscript as well as registering and using CDECL functions without failing on device, that would be a dream come true.

#15 Papirosnik   Members   -  Reputation: 125

Like
1Likes
Like

Posted 14 November 2012 - 03:54 PM

I have to say also that angelscript can work properly with marmalade.. with some finishing touches.
Firstly, .S file can't contain c++ comments (I wrote about this here: http://www.gamedev.net/topic/626036-compiling-for-marmalade-sdk/)
Secondly, it needs to use scons for Android or IOS builds (see http://www.madewithmarmalade.com/devnet/forum/angel-script for more details).

Edited by Papirosnik, 14 November 2012 - 03:57 PM.


#16 Andreas Jonsson   Moderators   -  Reputation: 3452

Like
1Likes
Like

Posted 14 November 2012 - 04:13 PM

Thanks for reminding me of the comments in the .S file, and for clarifying the need to use scons to build for Android and iOS.

I'll add this information to the manual in the article about compiling the library for Marmalade.

I don't want to remove the comments from the .S file. But perhaps there is another comment syntax that is acceptable when compiling with both Marmalade and gcc? Do you know what can be used instead of the C++ comments?
AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

#17 Martins Mozeiko   Crossbones+   -  Reputation: 1422

Like
1Likes
Like

Posted 14 November 2012 - 06:24 PM

You can use C comments - /* ... */
I'm not sure about Marmelade, but GNU assembler also accepts # as delimiter for comments - the rest of line after # symbol will be viewed as comment

#18 Andreas Jonsson   Moderators   -  Reputation: 3452

Like
0Likes
Like

Posted 15 November 2012 - 08:13 AM

Thanks. I think I'll try the # style then.

It would be good if someone using Marmalade can confirm that it actually works before I check in the changes.
AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

#19 Papirosnik   Members   -  Reputation: 125

Like
0Likes
Like

Posted 17 November 2012 - 06:23 AM

Thanks. I think I'll try the # style then.
It would be good if someone using Marmalade can confirm that it actually works before I check in the changes.


I just checked and can confirm that '//' comments are not allowed; using '#' instead '//' is allowed but only at the beginning of the line... arm assembler uses '#' as a part of operands.

'/*.. */' is allowed everywhere and probably would be the best solution.

Edited by Papirosnik, 17 November 2012 - 06:26 AM.


#20 Andreas Jonsson   Moderators   -  Reputation: 3452

Like
0Likes
Like

Posted 17 November 2012 - 08:13 AM

Thanks for confirming this. I'll make the necessary changes.

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




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS