Physics "broken" after going from release build to daily build

Hey guys, there’s been a while since I last updated one of the games I’m working on and today I tried to test it under the latest build (1191) only to find out a line of code related to adding a physics body to a line I’ve drawn on the screen crashes Corona Simulator with a segmentation fault.

The line of code is this one:

physics.addBody(newLine, “static”, { density = 1, friction = 0.5, bounce = 0, filter = lineCollisionFilter, shape = {0, 0, dist_x, dist_y, 0, 0} } )

Important notes:

  • Using Corona’s latest release build (1137) it works perfectly.

  • If I remove the shape argument it “works” by adding automatic square bodies to my lines. I would like to add bodies shaped exactly like my lines have been drawn.

I don’t know if you guys modified something in the physics module, but I would really like a way to achieve the same effect I had before.

Thanks

Hi @guilovsh,

I’m not sure which build this change was made, but basically you’re not supposed to add physics bodies to line objects. This might have been changed by the engineers for internal reasons related to the rendering system. I believe you’ll need to convert your line objects to newRects of the same width/height as your lines were representing.

Best regards,

Brent

That is terrible, Brent.

Unless I’m missing something, this means I would have to use newRects of minimum height and desired size and then rotate it by the angle formed from the first point of my line to the last.

Besides why would updates remove basic functionalities like that!? If there’s something wrong, you shouldn’t ever remove, but correct it O.o

Hi @guilovsh,

I understand your concern and it’s justified, but physics bodies + line vectors has never worked “out of the box” and was never really intended to. You can add a physics body to a line without specifying the corner points in the “shape” table, but the body will not be configured properly. Test the following code in #1137 in hybrid mode and you’ll see the result:

[lua]

local line = display.newLine(200,200,200,300) ; line.width = 4 ; line:setColor(255)

physics.addBody( line, “static” )

local line2 = display.newLine(300,200,400,300) ; line2.width = 4 ; line2:setColor(255)

physics.addBody( line2, “static” )

[/lua]

The results of then rotating that line object (and using collisions) will be unpredictable at best. Using rectangle objects, by contrast, will allow the shape to be auto-drawn (no need for specifying shape points), and the object will be compatible with full rotation.

I hope this explains it a little better,

Brent

But the thing is, I wouldn’t have to rotate my objects in my case, so why wouldn’t I use lines?

Besides, you can use the exact code you’ve sent in the latest build as well. It will only crash if you try to specify a shape that mimics a line.

And although I understand your explanation, I’m really disappointed since it isn’t the first time I’ll have to rewrite some of my code because of Corona’s changes, I’m already tired of telling my co-workers I’ll have to spend more time working in a feature because of the SDK I chose to use :confused: . After the third time it starts to sound to them like I’ve made a terrible choice and I can’t blame them for thinking that.

Thanks for your time anyway, Brent.

Have a good weekend.

Hi @guilovsh.

No one likes breaking changes.  I hate that they have to be there, but sometimes to move forward, we have to break things.  This isn’t a “Corona” thing.  Facebook breaks their SDK about every 3 months.  Twitter broke their API about 6 months ago.   As a software API provider, we can hope to minimize breaking changes and I think we do a good job of that.  Sometimes as consumers of the API we get used to using a behavior that we may like, understand, or fits our particular app, but we may be taking advantage of something that’s really a bug rather than the way it supposed to be.

This is one reason we don’t take down old builds.  If 1137 is working for you, perhaps you should continue to use it for this app and then use a more modern version for new apps.

I don’t remember the specifics around this particular fix (I don’t do a lot of physics work so I’m not as familiar with those issues), but its very possible the existence of putting bodies on lines was causing performance problems or crashes.

Hi @guilovsh,

I’m not sure which build this change was made, but basically you’re not supposed to add physics bodies to line objects. This might have been changed by the engineers for internal reasons related to the rendering system. I believe you’ll need to convert your line objects to newRects of the same width/height as your lines were representing.

Best regards,

Brent

That is terrible, Brent.

Unless I’m missing something, this means I would have to use newRects of minimum height and desired size and then rotate it by the angle formed from the first point of my line to the last.

Besides why would updates remove basic functionalities like that!? If there’s something wrong, you shouldn’t ever remove, but correct it O.o

Hi @guilovsh,

I understand your concern and it’s justified, but physics bodies + line vectors has never worked “out of the box” and was never really intended to. You can add a physics body to a line without specifying the corner points in the “shape” table, but the body will not be configured properly. Test the following code in #1137 in hybrid mode and you’ll see the result:

[lua]

local line = display.newLine(200,200,200,300) ; line.width = 4 ; line:setColor(255)

physics.addBody( line, “static” )

local line2 = display.newLine(300,200,400,300) ; line2.width = 4 ; line2:setColor(255)

physics.addBody( line2, “static” )

[/lua]

The results of then rotating that line object (and using collisions) will be unpredictable at best. Using rectangle objects, by contrast, will allow the shape to be auto-drawn (no need for specifying shape points), and the object will be compatible with full rotation.

I hope this explains it a little better,

Brent

But the thing is, I wouldn’t have to rotate my objects in my case, so why wouldn’t I use lines?

Besides, you can use the exact code you’ve sent in the latest build as well. It will only crash if you try to specify a shape that mimics a line.

And although I understand your explanation, I’m really disappointed since it isn’t the first time I’ll have to rewrite some of my code because of Corona’s changes, I’m already tired of telling my co-workers I’ll have to spend more time working in a feature because of the SDK I chose to use :confused: . After the third time it starts to sound to them like I’ve made a terrible choice and I can’t blame them for thinking that.

Thanks for your time anyway, Brent.

Have a good weekend.

Hi @guilovsh.

No one likes breaking changes.  I hate that they have to be there, but sometimes to move forward, we have to break things.  This isn’t a “Corona” thing.  Facebook breaks their SDK about every 3 months.  Twitter broke their API about 6 months ago.   As a software API provider, we can hope to minimize breaking changes and I think we do a good job of that.  Sometimes as consumers of the API we get used to using a behavior that we may like, understand, or fits our particular app, but we may be taking advantage of something that’s really a bug rather than the way it supposed to be.

This is one reason we don’t take down old builds.  If 1137 is working for you, perhaps you should continue to use it for this app and then use a more modern version for new apps.

I don’t remember the specifics around this particular fix (I don’t do a lot of physics work so I’m not as familiar with those issues), but its very possible the existence of putting bodies on lines was causing performance problems or crashes.

@  GUILOVSH

I am experiencing the same problem!!!   Please if you have solved this or found function that works please email me russm305@gmail.com with your solution.

I have 4 games that use a line drawing with physics.  I can not update any of them  because it will break.

Thank you!

Hi @russm305,

In the other thread, Bogdan and others seem to have no further issues using lines for physics “drawing” modules, so I don’t know why your code is crashing. It may be because you’re “overloading” the system by drawing lines literally every pixel of movement, instead of placing lines in a nice stop-gap formation. The code I gave you absolutely works (I tested it on my side) and does exactly that… it figures out when to place a new segment based on the distance from the previous one… and yes, that code sample uses rectangle “lines” instead of lines, but the principle of spacing them apart is in there.

Best regards,

Brent

@Brent

Got it to work thanks, your code didn’t work for my situation.   Good to see Corona finally admit to their mistakes and fix the problem and stop blaming Cocos2d.  Would have been nice if I was told this in my thread that it was going to be fixed.  

But im good to go now thank you!

@  GUILOVSH

I am experiencing the same problem!!!   Please if you have solved this or found function that works please email me russm305@gmail.com with your solution.

I have 4 games that use a line drawing with physics.  I can not update any of them  because it will break.

Thank you!

Hi @russm305,

In the other thread, Bogdan and others seem to have no further issues using lines for physics “drawing” modules, so I don’t know why your code is crashing. It may be because you’re “overloading” the system by drawing lines literally every pixel of movement, instead of placing lines in a nice stop-gap formation. The code I gave you absolutely works (I tested it on my side) and does exactly that… it figures out when to place a new segment based on the distance from the previous one… and yes, that code sample uses rectangle “lines” instead of lines, but the principle of spacing them apart is in there.

Best regards,

Brent

@Brent

Got it to work thanks, your code didn’t work for my situation.   Good to see Corona finally admit to their mistakes and fix the problem and stop blaming Cocos2d.  Would have been nice if I was told this in my thread that it was going to be fixed.  

But im good to go now thank you!