yoshinoToylogic / bulletsharp

Automatically exported from code.google.com/p/bulletsharp
MIT License
0 stars 0 forks source link

CollisionWorld.AllHitsRayResultCallback.HitPointWorld throws NullReferenceException #53

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
I'm trying to access the results of a raycast, but are getting some unexpected 
results.

I'm able to use CollisionWorld.ClosestRayResultCallback without issue, but 
CollisionWorld.AllHitsRayResultCallback throws a NullReferenceException when I 
try to access its array of hit points (its HitPointsWorld property).

Stranger still, the results are all-around inconsistent. For example: I can 
access HitPointsWorld.Count as expected, but comparing HitPointsWorld to null 
results in a true expression. Accessing any array elements throws an exception 
as well.

And the Visual Studio (2010) debugger is just as confused as I am. The 
inspector shows HitPointsWorld as null, but if I inspect the 
AllHitsRayResultCallback, HitPointsWorld magically becomes non-null.

I've attached a test scenario with two variations (one commented, the other 
left uncommented). Both variations are slightly different, but show that the 
results change depending on the order things are accessed.

BulletSharp version: 2.81 (Generic)

Original issue reported on code.google.com by shiny....@gmail.com on 9 Jun 2013 at 7:34

Attachments:

GoogleCodeExporter commented 8 years ago
So I looked at a decompilation of the HitPointWorld property (I've no idea how 
to go about doing it the right way).

Something about it appeared off. HitPointWorld returns a lazily-allocated 
array, but returns _hitNormalWorld if the array has already been allocated. So 
HitPointWorld was returning the correct array, but only the first time it was 
accessed. Subsequent accesses were returning an array that's part of 
HitNormalWorld and hadn't been allocated yet.

Case in point: HitPointWorld only returns the correct value the first time it's 
accessed. Further accesses to it return _hitNormalWorld instead, whether it has 
been allocated or not.

Knowing this, I cached the first value returned HitPointWorld and now raycasts 
work as intended. And there's a sizable comment there explaining why. Beware.

Original comment by shiny....@gmail.com on 9 Jun 2013 at 8:16

GoogleCodeExporter commented 8 years ago
Ah, this was fixed in r499.

Looks like it's time for another release :)

Original comment by andres.traks on 9 Jun 2013 at 10:02

GoogleCodeExporter commented 8 years ago
Nifty!

I built the latest revision from source and things are working fine.

Original comment by shiny....@gmail.com on 10 Jun 2013 at 3:20

GoogleCodeExporter commented 8 years ago

Original comment by andres.traks on 10 Jun 2013 at 6:14