CollidingPairskernel crash

A place to discuss everything related to Newton Dynamics.

Moderators: Sascha Willems, walaber

CollidingPairskernel crash

Postby Slick » Fri May 30, 2014 3:51 pm

This is my ongoing battle to get something working on Android.

I have had problems I think with threads but can't be sure. Sometimes it seems to just sit. Anyway, I currently have DG_USE_THREAD_EMULATION defined.

I also currently can't step through code because of my setup but I am getting a crash in CollidingPairskernel. I don't know if this is enough information to go on to try and point me in the direction of what to do.

Also, out of curiosity I think threads are supposed to work on Android so I have tried without DG_USE_THREAD_EMULATION and still haven't had any luck.
Slick
 
Posts: 330
Joined: Sat Feb 07, 2004 7:24 pm
Location: LA last and France now

Re: CollidingPairskernel crash

Postby Slick » Mon Jun 02, 2014 5:55 pm

I got debugging working. Here is where it crashes when updating the world.

This is after simply adding a sphere.
Last edited by Slick on Thu Jun 05, 2014 11:51 am, edited 1 time in total.
Slick
 
Posts: 330
Joined: Sat Feb 07, 2004 7:24 pm
Location: LA last and France now

Re: CollidingPairskernel crash

Postby Slick » Mon Jun 02, 2014 6:08 pm

Hmm I removed the sphere and I get the crash in the same spot. So this is an empty world crashing at that point. I'm beginning to think I may have built the library with some incorrect switch?
Slick
 
Posts: 330
Joined: Sat Feb 07, 2004 7:24 pm
Location: LA last and France now

Re: CollidingPairskernel crash

Postby Slick » Mon Jun 02, 2014 6:13 pm

In while ((index = dgAtomicExchangeAndAdd(&descriptor->m_pairsCount, -1)) > 0) {

descriptor->m_pairsCount evaluates to zero as I would guess with no objects. However, index does get assigned a value and it drops into the while loop which seems strange.
Slick
 
Posts: 330
Joined: Sat Feb 07, 2004 7:24 pm
Location: LA last and France now

Re: CollidingPairskernel crash

Postby Slick » Mon Jun 02, 2014 7:08 pm

Ok I worked it out. It looks the wrong intrinsics were being called in my setup.
Slick
 
Posts: 330
Joined: Sat Feb 07, 2004 7:24 pm
Location: LA last and France now

Re: CollidingPairskernel crash

Postby AntonSynytsia » Wed Jun 04, 2014 8:38 pm

So, you're saying Newton works on Android? :o

Can you give me more information on how you did it:
  • Did you compile Newton on Windows and copied the dll to Android?
  • Can Android run dlls?

I'm interested in that stuff because smart phones could become the feature PCs...
AntonSynytsia
 
Posts: 193
Joined: Sat Dec 28, 2013 6:36 pm

Re: CollidingPairskernel crash

Postby JoeJ » Thu Jun 05, 2014 1:12 am

To compile for Android on Windows you need Cygwin to emulate Linux and the Android NDK (coming with gcc for C++).
I think Nvidia provides easy install packages - keyword 'Tegra'. The ouput is named .so instead .dll
That allows to develop C/C++ for Android, but most probably you also need Eclipse + Android Plug-In for the Java part. (Included in the Nvidia package as well i think)
Newer versions of Android support Native Apps that do not require Java (I don't have experience with that).

iOs supports C++ out of the box, but you need to run OSX.
I have not compiled Newton for mobile, but both OS support pThreads, so it should be possible to get multi-threading working.
User avatar
JoeJ
 
Posts: 1453
Joined: Tue Dec 21, 2010 6:18 pm

Re: CollidingPairskernel crash

Postby AntonSynytsia » Thu Jun 05, 2014 4:35 am

JoeJ wrote:To compile for Android on Windows you need Cygwin


I got Cygwin installed how what commands do I type to get newton.so ?
AntonSynytsia
 
Posts: 193
Joined: Sat Dec 28, 2013 6:36 pm

Re: CollidingPairskernel crash

Postby JoeJ » Thu Jun 05, 2014 5:44 am

It's not as easy as you think :)

Cygwin alone is just a linux alike shell and file system.
Next you need the Android NDK (Native Dev. Kit) for the development tools like gcc compiler and linker...

But berfore you can do anything, you may wanna write a java hello world android activity, you need Eclipse and the Android Plug in & Java SDK.
Then you need to write a simple c program like return the square root of a float.
You tell NDK to include your source in some textfile.
Compiling that with a cygwin shell command like:

cd /cygdrive/c/dev/eclipse_workspace/test
/cygdrive/c/dev/android-ndk-r7/ndk-build

This builds test.so, which you also link by adding its name to a text file. (i forgot any details)
Then you can try to call this c function from Java.

Setting up all this alone should cost you a full day - maybe more (That's why i recommend the Nvidia Single Click Installer).
That's usually a frustrating experince, be warned. But there should be step by step tutorials.

I guess you'd need some experience with all this before you can compile a huge project like newton.
User avatar
JoeJ
 
Posts: 1453
Joined: Tue Dec 21, 2010 6:18 pm

Re: CollidingPairskernel crash

Postby Julio Jerez » Mon Jun 09, 2014 7:22 am

Slick wrote:In while ((index = dgAtomicExchangeAndAdd(&descriptor->m_pairsCount, -1)) > 0) {

descriptor->m_pairsCount evaluates to zero as I would guess with no objects. However, index does get assigned a value and it drops into the while loop which seems strange.


did you figure out what is the correct atomic?
in newton the dgAtomicExchangeAndAdd assume pre increment, but there are application that define atomic differently and since they is no standard that could cause problems, I assumed that
most platform use the POSIT defintion

the function defines like this
Code: Select all
DG_INLINE dgInt32 dgAtomicExchangeAndAdd (dgInt32* const addend, dgInt32 amount)
{
   // it is a pity that pthread does not supports cross platform atomics, it would be nice if it did
   #if (defined (_WIN_32_VER) || defined (_WIN_64_VER))
      return _InterlockedExchangeAdd((long*) addend, long (amount));
   #endif

   #if (defined (_MINGW_32_VER) || defined (_MINGW_64_VER))
      return InterlockedExchangeAdd((long*) addend, long (amount));
   #endif


   #if (defined (_POSIX_VER) || defined (_POSIX_VER_64) ||defined (_MACOSX_VER))
      return __sync_fetch_and_add ((int32_t*)addend, amount );
   #endif
}




The expect behavior is like this

Code: Select all
int dgAtomicExchangeAndAdd (int* ptr, int value)
{
     int ret = *ptr;
    *ptr += value;
     return value;
}


basically it add values to was was store in *ptr
and returns the value that was stored at *ptr before values was added

some implementation do it the other way, by returning the post incremented value and that will lead to bad bugs in newton
I hope you can test the atimic and see if work as it should
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: CollidingPairskernel crash

Postby Slick » Mon Jun 09, 2014 10:51 am

Julio Jerez wrote:did you figure out what is the correct atomic?


Yes I got it working in my very small test so far.
Slick
 
Posts: 330
Joined: Sat Feb 07, 2004 7:24 pm
Location: LA last and France now


Return to General Discussion

Who is online

Users browsing this forum: No registered users and 22 guests

cron