Last active
December 17, 2015 00:39
-
-
Save PDeveloper/5522253 to your computer and use it in GitHub Desktop.
Null reference error when using DYNAMIC_AABB_TREE after bodies fall asleep:
Compile + Run project
Wait for all bodies to fall asleep
Press space
IT WREAKS HAVOC! :S
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package ; | |
import flash.display.StageAlign; | |
import flash.display.StageScaleMode; | |
import flash.Lib; | |
import nape.geom.Vec2; | |
import nape.phys.Body; | |
import nape.phys.BodyType; | |
import nape.shape.Polygon; | |
import nape.space.Broadphase; | |
import nape.space.Space; | |
import nape.util.Debug; | |
/** | |
* ... | |
* @author P Svilans | |
*/ | |
class Main | |
{ | |
var isStatic:Array<Bool>; | |
var positions:Array<Vec2>; | |
var space:Space; | |
var debug:Debug; | |
var bodies:Array<Body>; | |
var steps:Int; | |
public function new() | |
{ | |
// Randomly generated values for body setup: | |
isStatic = [false, false, false, true, true, false, false, false];// new Array<Bool>(); | |
positions = [ Vec2.get( 365.17363637685776, 199.90923553705215), Vec2.get( 368.2230018079281, 260.8062478713691), Vec2.get( 274.02000427246094, 301.19895078241825), Vec2.get( 533.9017130434513, 317.3988307826221), Vec2.get( 359.2422803863883, 338.5915950872004), Vec2.get( 571.4873317629099, 250.75904969125986), Vec2.get( 320.33724319189787, 298.6354513093829), Vec2.get( 520.6472609192133, 172.14729264378548)]; | |
space = new Space( Vec2.weak( 0, 0), Broadphase.DYNAMIC_AABB_TREE); | |
bodies = new Array<Body>(); | |
for ( i in 0...8) | |
{ | |
var type:BodyType; | |
var body = new Body( BodyType.DYNAMIC, positions[i]); | |
body.shapes.add( new Polygon( Polygon.box( 200, 200, true))); | |
if ( isStatic[i]) type = BodyType.STATIC; | |
else type = BodyType.DYNAMIC; | |
body.type = type; | |
body.space = space; | |
bodies.push( body); | |
} | |
while ( space.liveBodies.length != 0) | |
{ | |
space.step( 1 / 30, 10, 10); | |
} | |
space.step( 1 / 30, 10, 10); // < NEED THIS | |
space.clear(); | |
space = new Space( new Vec2(), Broadphase.DYNAMIC_AABB_TREE); | |
for ( body in bodies) | |
{ | |
new Vec2(); | |
body.space = space; | |
} | |
space.step( 1 / 30, 10, 10); | |
} | |
static function main() | |
{ | |
var stage = Lib.current.stage; | |
stage.scaleMode = StageScaleMode.NO_SCALE; | |
stage.align = StageAlign.TOP_LEFT; | |
// entry point | |
new Main(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment