fix this broadphase crash

This commit is contained in:
RandomityGuy 2026-03-28 01:51:24 +00:00
parent a6ae9259a1
commit a87d31056b
2 changed files with 12 additions and 4 deletions

View file

@ -30,6 +30,14 @@ class Util {
return value; return value;
} }
public static inline function imin(a:Int, b:Int) {
return a < b ? a : b;
}
public static inline function imax(a:Int, b:Int) {
return a > b ? a : b;
}
public static inline function lerp(a:Float, b:Float, t:Float) { public static inline function lerp(a:Float, b:Float, t:Float) {
return a + (b - a) * t; return a + (b - a) * t;
} }

View file

@ -111,10 +111,10 @@ class GridBroadphase {
var queryMinY = Math.max(object.boundingBox.yMin, bounds.yMin); var queryMinY = Math.max(object.boundingBox.yMin, bounds.yMin);
var queryMaxX = Math.min(object.boundingBox.xMax, bounds.xMax); var queryMaxX = Math.min(object.boundingBox.xMax, bounds.xMax);
var queryMaxY = Math.min(object.boundingBox.yMax, bounds.yMax); var queryMaxY = Math.min(object.boundingBox.yMax, bounds.yMax);
var xStart = Math.floor((queryMinX - bounds.xMin) / this.cellSize.x); var xStart = Util.imax(0, Math.floor((queryMinX - bounds.xMin) / this.cellSize.x));
var yStart = Math.floor((queryMinY - bounds.yMin) / this.cellSize.y); var yStart = Util.imax(0, Math.floor((queryMinY - bounds.yMin) / this.cellSize.y));
var xEnd = Math.floor((queryMaxX - bounds.xMin) / this.cellSize.x); var xEnd = Util.imin(CELL_SIZE - 1, Math.floor((queryMaxX - bounds.xMin) / this.cellSize.x));
var yEnd = Math.floor((queryMaxY - bounds.yMin) / this.cellSize.y); var yEnd = Util.imin(CELL_SIZE - 1, Math.floor((queryMaxY - bounds.yMin) / this.cellSize.y));
var proxy = objectToProxy.get(object); var proxy = objectToProxy.get(object);
if (proxy == null) { if (proxy == null) {
insert(object); insert(object);