Jump to content

  • Log In with Google      Sign In   
  • Create Account

Interested in a FREE copy of HTML5 game maker Construct 2?

We'll be giving away three Personal Edition licences in next Tuesday's GDNet Direct email newsletter!

Sign up from the right-hand sidebar on our homepage and read Tuesday's newsletter for details!


We're also offering banner ads on our site from just $5! 1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


- - - - -

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

#21 UltimateWalrus   Members   -  Reputation: 196

Like
0Likes
Like

Posted 01 December 2012 - 08:28 PM

Hi Andreas,

Thanks very much for all your help, as well as IobuWu, Papirosnik, and Martins Mozeiko. However, even after trying everything, I am still unable to get anything but the generic calling convention working on an ARM processor. I've asked a question to Marmalade like you suggested.

I would love to help solve this as it'd make my life a whole lot easier, having chosen AngelScript as the scripting language for the game project I'm working on. The generic calling conventions are also a problem when using things like the "ref" type extension, which I need to let my game objects communicate, but I'll have to modify to use generic calling conventions if I can't solve the cdecl problem.

It appears that some of the suggestions in this thread may have been coded into the newest version of AngelScript (2.25.2) which I am now using. I still have made sure that MARMALADE and _ARM_ are getting defined by putting them into the project manually. Defining AS_NO_THREADS doesn't seem to be necessary anymore (though I have tried with and without). I tried using the *.S files instead of *.asm with scons as suggested (had to delete the comments as I couldn't figure out the correct syntax to change it to), unfortunately I still get the same runtime error when running the scons builds.

It doesn't seem that Marmalade defines _MSC_VER when compiling for ARM from within MSVC. It doesn't seem to define that either when compiling with scons. Perhaps this is the problem, as it gets into the other two just fine when I force that one to true. However, I can't simply do this to make it work as it seems to cause a domino-chain of other compiler errors that I can't fix without intimate knowledge of AngelScript's inner workings.

In an effort to make the problem as clear as possible I've put together a complete "Hello World" Angelscript/Marmalade project that should be runnable on any system with even the free trial of Marmalade installed (and MSVC). It's attached to this message. If this project worked without crashing on ARM it would be like gold to me (I've spent days trying to troubleshoot this). As it is now, here are instructions on how to reproduce the crash:

MSVC way:
1.) Double-click AngelScript_HelloWorld.mkb to open the project in MSVC.
2.) If you'd like, compile the debug or release version for x86 and run it. This is what's supposed to happen (a "Hello World" dialog)
3.) Compile the debug version using GCC(ARM). This should compile successfully.
4.) Hit F5 and this will start the special ARM simulator and debugger.
5.) To see the exact point of the problem, navigate to as_scriptengine.cpp and put a breakpoint on line 2473.
6.) Click "continue" and the program will hit the breakpoint (which means the error has occurred)

(note that _ARM_ isn't actually defined for the MSVC build as I haven't figured out how to do this for only one build with Marmalade. However, even if you explicitly declare _ARM_ in the project settings, the same error occurs because _MSC_VER isn't defined for the ARM compiler)

Scons way:
1.) Double-click the scons.bat file that I put in the same directory as the project files, this should compile to ARM files with scons.
2.) Navigate to the build_angelscript_helloworld_scons_scons_arm directory.
3.) Choose either debug or release directory.
4.) Copy the *.s3e file in that directory to the "data" directory under the project's folder. You can double-click it to run it from there (ignore the Marmalade warning message).
5.) You should get the same result as if you ran the ARM simulator from MSVC.
6.) If you want to debug, you should be able to click the *.s3e file and click "debug." Then you can point the ARM simulator to the generated *.elf file in the directory where the build came from.

That is the situation as best as I've been able to understand it. I hope that this leads to a solution. I've been very happy with AngelScript so far, it's just this calling convention problem that's been driving me up a wall.

Thank you very much,
Sebastian

Attached Files



Sponsor:

#22 Andreas Jonsson   Moderators   -  Reputation: 3413

Like
1Likes
Like

Posted 02 December 2012 - 09:43 AM

From what we've learned earlier from papirosnik and loboWu, when compiling for ARM scons must be used, so I suggest you concentrate your efforts on that and leave trying to get it to work with MSVC for later.

Do you expect this to run on iOS or Android? I don't think Marmalade defines either when compiling for arm, which will leave the configuration in AngelScript only partly defined.

Try including ANDROID or __APPLE__ and TARGET_OS_IPHONE, i.e.

defines
{
MARMALADE
_ARM_
ANDROID
}

or

defines
{
MARMALADE
_ARM_
__APPLE__
TARGET_OS_IPHONE
}

In loboWu's makefile I see he defined AS_ARM directly to enable the as_callfunc_arm.cpp. But this would bypass all other configuration in as_config.h so this is not recommended. However, if none of the above works, you might try that as well.

Observe, iOS and Android uses slightly different calling conventions and I have no idea which Marmalade uses (or even if it isn't using a completely different calling convention) so you may need to try both to see which works best.
AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

#23 UltimateWalrus   Members   -  Reputation: 196

Like
0Likes
Like

Posted 02 December 2012 - 11:29 AM

Hi Andreas, thanks for the response. I would like to be able to make builds for both iOS and Android. I tried both those suggestions and got compiler errors.

With Android define:
as_callfunc.cpp:476: error: exception handling disabled, use -fexceptions to enable

I figure I am supposed to add that command line flag somehow, but I can't figure it out. Neither:

AngelScript_HelloWorld_scons.mkb --arm --buildenv=scons --compiler=gcc --cppflag=-fexceptions

nor:

AngelScript_HelloWorld_scons.mkb --arm --buildenv=scons --compiler=gcc -fexceptions

seem to work.


With iPhone defines:
as_config.h:583: fatal error: TargetConditionals.h: No such file or directory

My guess is that this is an apple-specific library that I should probably be able to include as a subproject with Marmalade, but I don't know what subproject to use. Should I ask another question to Marmalade?


The way the Marmalade SDK works, it seems to compile a single ARM binary, and be able to "package" it up for use with either iOS or Android without the need for a recompile. So if the systems are slightly different, you may be right be right that Marmalade has a favorite, though it's not clear yet which one that might be.

#24 Andreas Jonsson   Moderators   -  Reputation: 3413

Like
1Likes
Like

Posted 02 December 2012 - 12:01 PM

From loboWu's makefile I see that exceptions are enabled like this:

#!/usr/bin/env mkb


options
{
   enable-exceptions=1
   lib
   module_path="../../source"
}

Did you try defining AS_ARM directly? Like loboWu does in his makefile? What was the result of that?
AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

#25 UltimateWalrus   Members   -  Reputation: 196

Like
0Likes
Like

Posted 02 December 2012 - 01:02 PM

I played around with AS_ARM and it didn't seem to help. However, using the following defines/options:

defines
{
MARMALADE
_ARM_
ANDROID
}

options
{
enable-exceptions=1
}

It seems that, when compiling with SCons, the ARM versions are finally working properly! Since Marmalade's ARM binaries are theoretically platform independent, I may be able to "package" the binary up for iOS as well.

Thanks a ton for all your help. It seems my troubles may finally be over, though I need to verify everything works on device. Once I can confirm everything's working I'll try and clean up the Hello World program and post it for anyone who might need it in the future. Will post again with results.

---Sebastian

#26 Andreas Jonsson   Moderators   -  Reputation: 3413

Like
0Likes
Like

Posted 02 December 2012 - 01:39 PM

Great to hear it is finally working.

Do let me know if you encounter other problems.

I'll probably have to include a Marmalade makefile for the AngelScript library, especially since it is not so straightforward to figure out how to configure it.
AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

#27 UltimateWalrus   Members   -  Reputation: 196

Like
1Likes
Like

Posted 03 December 2012 - 05:41 PM

Yep, it's working, and I'm finally able to run AngelScript on device using CDECL calling conventions. :]

Thanks a ton for all your help. Attached is a complete Marmalade project that implements "Hello World" by calling a print function from AngelScript, and runs just fine on devices without the asCALL_GENERIC workaround. Should save some time if anyone else needs to get AngelScript/Marmalade working in the future. You're welcome to reference it if you wanna put Marmalade makefiles in the AngelScript library.

Attached Files



#28 Braden M   Members   -  Reputation: 126

Like
0Likes
Like

Posted 04 December 2012 - 05:18 PM

Hi everyone,

I want to say a big thank you to all of you for your hard work in getting AngelScript to work on Marmalade. Unaware of UltimateWalrus's latest posts, I spent some time last week integrating AngelScript into Marmalade, and have put together yet another integration of AngelScript and Marmalade: angelscript-marmalade project on GitHub.

It seems to be working well on MSVC/x86, VS/GCC-ARM, XCode/Clang/x86, XCode/GCC/x86, XCode/ARM, and Scons/ARM. I've included portable binaries in the distribution so that it can be used right away. If one does want to [re-]compile it, it should compile easily and run with native calling conventions on Marmalade Windows, Marmalade Mac, or Marmalade ARM. (Although due to the presence of the ".S" files, one line of the MKB must be commented out before it will compile with Visual Studio). I made sure that the AngelScript code is completely unmodified; in fact, if you use the MKB to build the project, it will download the unmodified source upstream code as part of the build process.

I'm just getting started with AngelScript, but everything looks very promising so far. Just wanted share my code and to say thanks Posted Image

#29 Andreas Jonsson   Moderators   -  Reputation: 3413

Like
1Likes
Like

Posted 04 December 2012 - 06:56 PM

Hi Braden,

thanks for sharing your work and for letting us know that it works on all these different platforms.

There are now quite a few projects using AngelScript with Marmalade. Posted Image

I see that you use a couple of predefines to determine the target platform, i.e. I3D_ARCH_X86 and I3D_ARCH_ARM. How did you find out about these? It looks like something I can use directly within the as_config.h so it wouldn't be necessary to define anything other than MARMALADE from the project files.

Actually perhaps I can even use the existance of I3D_ARCH_X86 or I3D_ARCH_ARM to identify that the library is being compiled for Marmalade, in which case it wouldn't be necessary to define anything at all from the Marmalde makefile.

Regards,
Andreas

Edited by Andreas Jonsson, 04 December 2012 - 07:04 PM.

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

#30 Braden M   Members   -  Reputation: 126

Like
1Likes
Like

Posted 04 December 2012 - 07:41 PM

That is an excellent idea: You could use (I3D_ARCH_X86 || I3D_ARCH_ARM) as a test for the Marmalade platform. It would be nice to remove the predefines from the MKB makefile if possible. I found out about these defines from the Marmalade forum; they are not in the documentation, although they have been around for a long time. (Unfortunately there are quite a few of these little Marmalade "tricks" that are completely undocumented except for the occasional insightful forum post from Marmalade staff.)

Edit: It's worth mentioning that Marmalade also supports other platforms (although they're not nearly as popular as x86 and ARM); their preprocessor definitions are: I3D_ARCH_AMD64, I3D_ARCH_MIPS, I3D_ARCH_PS3, I3D_ARCH_X360, and I3D_ARCH_PSP. I've never worked with any of those other platforms. The full list of symbols can be seen in the "temp_defines_debug.h" file that Marmalade's makefile_builder creates during the build process.

Edit 2: Upon looking at that file further, I see that you could also detect the Marmalade platform by looking for "IW_SDK", "__S3E__", or any number of other definitions. Check out this copy of an example temp_defines_debug.h file to see.

Edited by Braden M, 04 December 2012 - 08:02 PM.


#31 Andreas Jonsson   Moderators   -  Reputation: 3413

Like
0Likes
Like

Posted 05 December 2012 - 06:29 AM

Great. It looks like __S3E__ is a useful define to look for to identify Marmalade. With this it should no longer be necessary to manually define Marmalade anywhere. I3D_ARCH_ARM and I3D_ARCH_X86 etc will be used to determine for which CPU the library is compiled, and will control the code for the native calling conventions.

I'll make the necessary changes in the as_config.h, and let you know when it's checked in.
AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

#32 Andreas Jonsson   Moderators   -  Reputation: 3413

Like
0Likes
Like

Posted 05 December 2012 - 05:48 PM

I've checked in the changes in revision 1490.

It should no longer be necessary to make any defines to compile AngelScript for Marmalade. Please give it a try and let me know if there are any problems.

Based on the tests that UltimateWalrus had made, I configured Marmalade to use the same ABI as is used for Android. It's possible that later on you'll find some functions that don't work properly if this assumption is incorrect. If that happens, please tell me and I'll make the necessary changes in the library.
AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

#33 Braden M   Members   -  Reputation: 126

Like
0Likes
Like

Posted 06 December 2012 - 05:05 PM

Thanks Andreas! I really appreciate how responsive you are with fixes to AngelScript. I just tried out r1490 and it works perfectly as far as I can tell. I've put the new MKB in a separate branch for now, and I'll update "master" once 2.26 is released. The only "tweak" that I had to leave in was a definition of "fopen_s" that I put in preinclude.h, because Marmalade's standard library doesn't have that function available, even in Visual Studio.

Also, FYI, there are two compiler warnings that come up with Marmalade's ARM GCC4.4 (arm-none-eabi-g++); the first one looks like it could possibly affect bytecode output so I'll mention it in case you weren't aware of it.

angelscript/source/as_bytecode.cpp: In member function 'void asCByteCode::DebugOutput(const char*, asCScriptEngine*, asCScriptFunction*)':
angelscript/source/as_bytecode.cpp:2114: warning: format '%3d' expects type 'int', but argument 3 has type 'long unsigned int'


add_on/scripthelper/scripthelper.cpp: In function 'int WriteConfigToFile(asIScriptEngine*, const char*)':
add_on/scripthelper/scripthelper.cpp:194: warning: format '%X' expects type 'unsigned int', but argument 3 has type 'asDWORD'
The second warning occurs a total of ten times at different lines in scripthelper.cpp.

#34 Andreas Jonsson   Moderators   -  Reputation: 3413

Like
0Likes
Like

Posted 06 December 2012 - 05:54 PM

Thanks, these last issues should now be fixed in revision 1493.

You should not need the fopen_s tweak anymore. I had forgotten a few places were I was using fopen_s. These are in either case only used when compiling the library in debug mode.
AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

#35 Braden M   Members   -  Reputation: 126

Like
0Likes
Like

Posted 19 December 2012 - 01:58 PM

Hi Andreas, I just found two more places where fopen_s is still causing that error even with the latest revision (if I omit the preinclude.h file) - both in add_ons:

scriptfile/scriptfile.cpp (line 320)
scripthelper/scripthelper.cpp (line 169)

#36 Andreas Jonsson   Moderators   -  Reputation: 3413

Like
0Likes
Like

Posted 19 December 2012 - 03:27 PM

Thanks. I'll have these fixed the same way (by adding a check for #if defined(__S3E__))
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