Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Crash with physics and mass

edited March 2013 in Bugs Posts: 5

In my setup() I am initializing an object that has the following code:

local defPoints = {vec2(0,5), vec2(3,0), vec2(-3,0), vec2(0,5)}
self.body = physics.body(POLYGON, unpack(defPoints))
self.body.mass = 1

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"
    )

Comments

  • dave1707dave1707 Mod
    Posts: 9,590

    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
  • IgnatzIgnatz Mod
    Posts: 5,396

    While you're waiting for an answer, please tell me how you get to see the console output?

  • Posts: 2,820

    @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!

  • Posts: 5

    You can view console output in Xcode (in the Organizer). Really useful.

  • IgnatzIgnatz Mod
    edited March 2013 Posts: 5,396

    @zoyt - ta, that is useful, it should be in the FAQ!

    @Cplr - What Organizer?

  • Posts: 521

    If running Xcode on your computer and the iPad is connected you can select windows -> organizer

  • Posts: 5

    Just a quick follow up, you can work around this crash by setting the density instead of mass.

  • edited April 2013 Posts: 489

    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
  • JohnJohn Admin Mod
    Posts: 643

    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.

Sign In or Register to comment.