Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

iphone4: sensor doesn't fire BeginContact #29

Open
GoogleCodeExporter opened this issue Aug 24, 2015 · 12 comments
Open

iphone4: sensor doesn't fire BeginContact #29

GoogleCodeExporter opened this issue Aug 24, 2015 · 12 comments

Comments

@GoogleCodeExporter
Copy link

What steps will reproduce the problem?
1. Create ball, wall and sensor (in between ball and wall)
2. Apply impulse to ball to travel through sensor towards wall
3.

What is the expected output? What do you see instead?
Should see BeginContact fired when ball goes through sensor, and when it hits 
the wall. But it doesn't fire when the ball goes through the sensor.

What version of the product are you using? On what operating system?
Using Box2dWeb-2.1.a.3.js on iOS4.2.1

Please provide any additional information below.
Code is attached, unpack and upload to your server, then access index.html in 
your browser

Original issue reported on code.google.com by threegar...@gmail.com on 9 Mar 2012 at 8:55

Attachments:

@GoogleCodeExporter
Copy link
Author

Forgot to mention, you need to enable the debug console. When BeginContact is 
fired, you'll see a debug message. You get 2 on firefox and all other desktop 
browsers, but only 1 on iOS.

Original comment by threegar...@gmail.com on 9 Mar 2012 at 11:23

@GoogleCodeExporter
Copy link
Author

I'm seeing the same behavior on my iPad. Sensors work fine in desktop browers, 
but not on iPhone/iPad.

Original comment by luke.lut...@gmail.com on 4 Apr 2012 at 3:27

@GoogleCodeExporter
Copy link
Author

The issue is that Number.MIN_VALUE === 0 on iOS

Original comment by rwa...@gmail.com on 19 Apr 2012 at 7:17

@GoogleCodeExporter
Copy link
Author

Anywhere that you multiply by Number.MIN_VALUE could fail because the result 
will always be 0 (in this case distance is not going to be less than 0)...

<= might work as a quick fix


   b2Shape.TestOverlap = function (shape1, transform1, shape2, transform2) {
      var input = new b2DistanceInput();
      input.proxyA = new b2DistanceProxy();
      input.proxyA.Set(shape1);
      input.proxyB = new b2DistanceProxy();
      input.proxyB.Set(shape2);
      input.transformA = transform1;
      input.transformB = transform2;
      input.useRadii = true;
      var simplexCache = new b2SimplexCache();
      simplexCache.count = 0;
      var output = new b2DistanceOutput();
      b2Distance.Distance(output, simplexCache, input);
      return output.distance < 10.0 * Number.MIN_VALUE;
   }

Original comment by rwa...@gmail.com on 19 Apr 2012 at 7:20

@GoogleCodeExporter
Copy link
Author

My solution was to define Box2d.MIN_VALUE in the first scope closure:

   a2j.MIN_VALUE = Number.MIN_VALUE;
   var d = 2;
   while (a2j.MIN_VALUE === 0) {
      a2j.MIN_VALUE = 1/(Number.MAX_VALUE/d);
      d *= 2;
   }

then replace all the Number.MIN_VALUE 's with Box2D.MIN_VALUE


Original comment by rwa...@gmail.com on 19 Apr 2012 at 8:03

@GoogleCodeExporter
Copy link
Author

Original comment by Uli.He...@googlemail.com on 24 Apr 2012 at 4:20

  • Changed state: Accepted

@GoogleCodeExporter
Copy link
Author

Using Number.MIN_VALUE is problematic even in the browser. It appears there are 
places where it's being used to compensate for round-off error like: 
1.0 - 100.0 * Number.MIN_VALUE < minTOI

In the browser Number.MIN_VALUE is 5e-324. This is way less than the precision 
of a float, so subtracting 100 times this from 1 is just 1. You can test this 
in the browser console by typing:
(1.0 - 100.0 * Number.MIN_VALUE) < 1

That will return false. In my case, minTOI very rarely comes out to 
0.9999999999999996. It appears that this is as close to 1 as the solver can get 
with the given geometry. It never exits the solving loop and my program hangs.

It turns out the smallest x such that "(1-x) < 1" returns true is 2^-53 or 
1.1102230246251565e-16. That might be a good replacement for at least some of 
the Number.MIN_VALUEs. I suspect that even though a JavaScript number can 
approach Number.MIN_VALUE, any round-off error in a box2d calculation that 
produces a deviation from 0 will exceed that value by hundreds of orders of 
magnitude.

Original comment by a...@carbonfive.com on 30 Aug 2012 at 1:13

@GoogleCodeExporter
Copy link
Author

Hey is ther e a solution to this? I have the same problem.

Original comment by adgholl...@gmail.com on 27 Feb 2013 at 6:15

@GoogleCodeExporter
Copy link
Author

My solution (#5) at least got sensors firing on iOS. If someone would like to 
update the library to not use Number.MIN_VALUE that'd be fine too.

Original comment by rwa...@gmail.com on 28 Feb 2013 at 5:35

@GoogleCodeExporter
Copy link
Author

Confirm that the fix in #5 worked for me as well. This was crucial for my 
project to succeed at all, kindly request that it be applied to distribution 
version.

Original comment by mikael.h...@gmail.com on 16 Sep 2013 at 6:35

@GoogleCodeExporter
Copy link
Author

Tried both solutions #5 and #7 both Chrome 26.0.1410.63 and Firefox 24.0 on 
Kubuntu 12.10, but no luck. b2Shape.TestOverlap still returns false when it 
should return true and my sensors still do not trigger.

Original comment by vdb...@gmail.com on 2 Oct 2013 at 8:36

@GoogleCodeExporter
Copy link
Author

To confirm #5 worked for me too. 

(however I can only replicate this error on iPad Chrome 34.0.1847.18, On iPhone 
5s with chrome it works without the patch)

Original comment by jamessim...@gmail.com on 18 May 2014 at 9:10

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant