Gamua / Starling-Framework

The Cross Platform Game Engine
http://www.starling-framework.org
Other
2.85k stars 819 forks source link

starling.utils.Pool.as - Null pointer exception #907

Closed zerobyted closed 7 years ago

zerobyted commented 7 years ago

This method checks sPoints but pop() from sPoints3D. Cause Nullpointer sometimes

        public static function getPoint3D(x:Number = 0, y:Number = 0, z:Number = 0):Vector3D
        {
            if (sPoints.length == 0) return new Vector3D(x, y, z);
            else
            {
                var point:Vector3D = sPoints3D.pop();
                point.x = x; point.y = y; point.z = z;
                return point;
            }
        }
JohnBlackburne commented 7 years ago

That should not be possible, the code you quote should work: either length is zero or non-zero.

Except if you were calling it from two different threads, or (in Flash’s case) two different event handlers at once. If you e.g. have an ENTER_FRAME event that does some processing and a TOUCH event that does more, Flash does nothing to stop them accessing the same data and causing problems like this. The fix is to do all your processing in one event/thread, e.g. the ENTER_FRAME one, and use the TOUCH event handler just to store events which the ENTER_FRAME handler later processes.

zerobyted commented 7 years ago

I dont call this method. I get "nullpointer" sometimes on tween Sprite3d with Feather's TextInput inside. Code work fine when both (2d and 3d) pools are empty or full. 3D points pool must be in: private static var sPoints3D:Vector.<Vector3D> = new <Vector3D>[]; but "getPoint3D(..)" check length of private static var sPoints:Vector.<Point> = new <Point>[];

Result:

 if (sPoints.length > 0 && sPoints3D.length == 0) {
     var point:Vector3D = sPoints3D.pop();
     point.x = x; // <<< Nullpointer
}
PrimaryFeather commented 7 years ago

Ah, you're right ... I had to read over the code three times before I saw what you were explaining ... (just as you, John :wink:) that I'm doing the length check on the wrong vector.

Thanks for the report, I'll fix that!

JohnBlackburne commented 7 years ago

Ah, yes. In both posts I failed to spot the problem, and thought the code fine, hence my reply. Familiar with that sort of bug in my own code: I can stare at it for ages and not spot a problem that is right in front of me.

PrimaryFeather commented 7 years ago

Haha, yes, I guess that's happening to every developer now and then! :wink:

In any case, it's fixed! Thanks a lot for the bug report!