Rube scene loader not working for Android

General discussion about the R.U.B.E editor
Post Reply
kyle.bong2@gmail.com
Posts: 41
Joined: Thu May 29, 2014 5:01 am

Rube scene loader not working for Android

Post by kyle.bong2@gmail.com »

Hi all,

I am seeing weird issue using Rube with Android and completely work fine with iOS. I have a simple chain like below and output from j2b2Fixture method extracting the value from json differs in iOS and Android.

Looks like call to Value::asFloat method in Android not converting float correctly from json in jsoncpp.cpp or the json parsing is not working correctly.



Please see below code and screen below. I have also included RUBE file.

Does anyone know how to fix this issue?

Much Thanks!

I am using:
rube 1.6.0
box2d 2.3.0
cocos2d-x 3.2 c++
Android NDK r9d

Code: Select all


Rube
"chain" : 
{
	"vertices" : 
	{
		"x" : 
		[
			-0.5,
			11.15591812133789,
			25.68233299255371,
			34.99306106567383,
			40.65397644042969
		],
		"y" : 
		[
			0.0,
			-1.931770443916321,
			2.137893199920654,
			2.026164293289185,
			7.202928543090820
		]
	}
}

iOS
cocos2d: x: -0.500000 x: 0.000000
cocos2d: x: 11.155918 y: -1.931770
cocos2d: x: 25.682333 y: 2.137893
cocos2d: x: 34.993061 y: 2.026164
cocos2d: x: 40.653976 y: 7.202929

Android
10-29 14:42:42.557: D/CCFileUtilsAndroid.cpp(25669): relative path = untitled2.json
10-29 14:42:42.557: D/cocos2d-x debug info(25669): x: -0.500000 y: 0.000000
10-29 14:42:42.557: D/cocos2d-x debug info(25669): x: 11.155918 y: -inf
10-29 14:42:42.557: D/cocos2d-x debug info(25669): x: -inf y: inf
10-29 14:42:42.557: D/cocos2d-x debug info(25669): x: inf y: 2.026164
10-29 14:42:42.557: D/cocos2d-x debug info(25669): x: 40.653976 y: 7.202929

rubeXXX.PNG
rubeXXX.PNG (213.1 KiB) Viewed 13712 times
untitled2.rube
(2.59 KiB) Downloaded 833 times


EDITED -

Playing with this issue, if I edit the floating point precision in RUBE exported json file (see below) it works!

How can I export json file with smaller precision? Is this the correct fix?

Code: Select all


"x" : 
		[
			-0.5,
			11.15591812133789,
			25.68233299255371,
			34.99306106567383,
			40.65397644042969
		]

to

"x" : 
		[
			-0.5,
			11.155,
			25.682,
			34.993,
			40.653
		]

EDITED AGAIN -

I found the issue Reader::decodeDouble in jsoncpp.cpp not working correctly for Android. For example 'value' will be "-inf" for example below. Not sure why :(

Code: Select all

 double value = 0;
 sscanf( "25.68233299255371", "%lf", &value );

// value = -inf
iforce2d
Site Admin
Posts: 861
Joined: Sat Dec 22, 2012 7:20 pm

Re: Rube scene loader not working for Android

Post by iforce2d »

Yes, that sure is weird. I can't really see what would be causing that... it's all exactly the same source code on both OSs right?

One thing you could try is the hexadecimal export format (in the Scene settings dialog under the Export options tab, uncheck the "Use human-readable floats in JSON").

If the problem is 100% repeatable, the only other thing I could suggest is to step through the program with the debugger to see where the first "inf" appears from.
kyle.bong2@gmail.com
Posts: 41
Joined: Thu May 29, 2014 5:01 am

Re: Rube scene loader not working for Android

Post by kyle.bong2@gmail.com »

Correct exactly the same code for both iOS and Android.

Wohoo hexadecimal export format worked! Been at this thingy for days :cry: Weird it didn't worked the other way. I even tried it with different machines and cocos2d-x versions. Very odd!

Much thanks!
iforce2d
Site Admin
Posts: 861
Joined: Sat Dec 22, 2012 7:20 pm

Re: Rube scene loader not working for Android

Post by iforce2d »

This might be relevant: https://code.google.com/p/android/issue ... l?id=77988

btw that thread seems to be talking about Android 5, which OS version are you seeing this problem on?
kyle.bong2@gmail.com
Posts: 41
Joined: Thu May 29, 2014 5:01 am

Re: Rube scene loader not working for Android

Post by kyle.bong2@gmail.com »

I am seeing it on Amazon kindle fire and Nexus 7 2 Android 4.x. Sounds like from your link it's problem with Android NDK.
kyle.bong2@gmail.com
Posts: 41
Joined: Thu May 29, 2014 5:01 am

Re: Rube scene loader not working for Android

Post by kyle.bong2@gmail.com »

NDK 10 fixed the problem.
Post Reply