It seems that the last line causes the crash as soon as I try to run the project (I disabled everything in my draw() to make sure it wasn’t something else causing the crash - commenting out the last line does in fact fix the crash). I get the following on my device’s console output:
Mar 18 10:52:53 MA-iPad-mini Codea[13454] <Error>: libMobileGestalt copySystemVersionDictionaryValue: Could not lookup ReleaseType from system version dictionary
??Mar 18 10:52:53 MA-iPad-mini Codea[13454] <Warning>: (
0
)
??Mar 18 10:52:53 MA-iPad-mini Codea[13454] <Warning>: (
0,
"0.5"
)
I was able to recreate the crash also. I was able to make it work with the POLYGON if I had a vec2 in each of the 4 quadrants. Basically a square around 0,0. If I shifted the points so they were in 1 quadrant, Codea crashed.
-- create a square with a point in each of the 4 quadrants
local defPoints = {vec2(-5,5),vec2(-5,-5),vec2(5,-5),vec2(5,5)} -- this works
-- shift the square by 5 in x and y direction, square in 1st quadrant
local defPoints = {vec2(0,10),vec2(0,0),vec2(10,0),vec2(10,10)} -- this crashes
@Ignatz - Go to Settings>General>About>Diagnostics & Usage>Diagnostics & Usage Data>Codea-%date%_%iPad name%.
Make sure your are not automatically sending Diagnostics & Usage to apple to view it.
Hope that helps!
Whatever is causing the crash seems to depend on the polygon’s size (update: when it is less than 1 square meter, given the scale of 32 pixels per meter?), based on experiments with the following rig:
supportedOrientations(LANDSCAPE_ANY)
function setup()
stroke(255)
strokeWidth(5)
rectMode(CENTER)
fontSize(32)
parameter.boolean("isSettingMass", false)
parameter.integer("size", 10, 20, 16)
parameter.integer("dx", -200, 200, 0)
parameter.integer("dy", -200, 200, 0)
end
function draw()
background(0)
stroke(0, 255, 0)
line(0, HEIGHT / 2, WIDTH, HEIGHT / 2)
line(WIDTH / 2, 0, WIDTH / 2, HEIGHT)
fill(255, 255, 0)
text("Touch Viewer to trigger physics.body", WIDTH / 2, HEIGHT - 50)
translate(WIDTH / 2, HEIGHT / 2)
stroke(255)
noFill()
rect(dx, dy, size * 2, size * 2)
end
function touched(touch)
if touch.state ~= ENDED then return end
local dp = vec2(dx, dy)
print("Setting physics.body!")
b = physics.body(POLYGON,
vec2(size, size) + dp, vec2(-size, size) + dp,
vec2(-size, -size) + dp, vec2(size, -size) + dp)
if isSettingMass then
print("Setting mass!")
b.mass = 1 -- Will crash Codea if size < 16
-- and (0, 0) not within polygon
end
end
```
This is a known issue with Box 2D regarding small objects with their origin too far away from the center of mass (rounding errors causing negative rotational inertia). I will look into trying to stop Codea from crashing as a result.