love.physics causes C++ errors.

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Socks
Prole
Posts: 14
Joined: Sat Dec 04, 2010 2:12 am

love.physics causes C++ errors.

Post by Socks »

I commented out this line:

Code: Select all

shapes[newbody] = love.physics.newRectangleShape(bodies[newbody],0,0,rx,ry,0)
And it seemed to continue normal (for not having that line, of course)
Here's some of the rest of the code to pair it:

Code: Select all

function love.update()
if _mode == "Game" then
if love.mouse.isDown("l") then
buffer = "\n"
draw = true
if fx == 0 and fy == 0 then
fx,fy = love.mouse.getX(),love.mouse.getY()
end
rx,ry = love.mouse.getX() - fx,love.mouse.getY() - fy
else
draw = false
--I added the next parts and it borked
newbody = #bodies + 1
graphics[#graphics + 1] = {fx,fy,rx,ry}
bodies[newbody] = love.physics.newBody(world,fx,fy,0,10)
shapes[newbody] = love.physics.newRectangleShape(bodies[newbody],0,0,rx,ry,0)
bodies[newbody]:setMassFromShapes()
fx,fy,rx,ry = 0,0,0,0
end
end
end
It resulted in several errors in a loop.
:P
:P
lovewat.png (211.24 KiB) Viewed 3854 times
What am I doing wrong?
:p
User avatar
bartbes
Sex machine
Posts: 4946
Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:

Re: love.physics causes C++ errors.

Post by bartbes »

The square is too small, that's what's causing the errors, as to why it results in such a crash, and not a love error, it is a known bug, but it's very tedious to remove, we'll get to it.. I promise..
Socks
Prole
Posts: 14
Joined: Sat Dec 04, 2010 2:12 am

Re: love.physics causes C++ errors.

Post by Socks »

I should probably have said that as soon as "_mode" is set to "Game", the errors pour in. I don't make any squares before this happens.

Edit:
Oh, I understand!
:p
User avatar
bmelts
Party member
Posts: 380
Joined: Fri Jan 30, 2009 3:16 am
Location: Wiscönsin
Contact:

Re: love.physics causes C++ errors.

Post by bmelts »

My guess is that sometimes, rx and ry can be negative (if you move the mouse left/up), which means you're trying to create a rectangle with negative width/height. I can't imagine box2d likes that.
Socks
Prole
Posts: 14
Joined: Sat Dec 04, 2010 2:12 am

Re: love.physics causes C++ errors.

Post by Socks »

I figured it out. The "if love.mouse.isDown("l") ... else" wasn't specific enough, and it ran though and created a box with 0 x and 0 y.
Thanks for your help!
:p
Socks
Prole
Posts: 14
Joined: Sat Dec 04, 2010 2:12 am

Re: love.physics causes C++ errors.

Post by Socks »

Don't mean to double post and be offtopic, but when I spawn the shapes, they don't move.
:p
User avatar
TechnoCat
Inner party member
Posts: 1611
Joined: Thu Jul 30, 2009 12:31 am
Location: Milwaukee, WI
Contact:

Re: love.physics causes C++ errors.

Post by TechnoCat »

Can you post the inflicted code?
Socks
Prole
Posts: 14
Joined: Sat Dec 04, 2010 2:12 am

Re: love.physics causes C++ errors.

Post by Socks »

I figured this would be it:

Code: Select all

newbody = #bodies + 1
graphics[#graphics + 1] = {fx,fy,rx,ry}
bodies[newbody] = love.physics.newBody(world,fx,fy,0,10)
shapes[newbody] = love.physics.newRectangleShape(bodies[newbody],0,0,rx,ry,0)
bodies[newbody]:setMassFromShapes()
fx,fy,rx,ry = 0,0,0,0
But I also have this...

Code: Select all

function love.draw()
love.graphics.print(table.concat(output,buffer),x,y)
for i,x in pairs(shapes) do
x1, y1, x2, y2, x3, y3, x4, y4 = x:getBoundingBox() --I cheated here.
boxwidth = x3 - x2
boxheight = y2 - y1
love.graphics.setColor(72, 160, 14)
love.graphics.rectangle("fill", bodies[i]:getX() - boxwidth/2, bodies[i]:getY() - boxheight/2, boxwidth, boxheight)
love.graphics.setColor(255, 255, 255)
end
end
No errors, but the new parts don't move at all.
:p
User avatar
TechnoCat
Inner party member
Posts: 1611
Joined: Thu Jul 30, 2009 12:31 am
Location: Milwaukee, WI
Contact:

Re: love.physics causes C++ errors.

Post by TechnoCat »

Code: Select all

bodies[newbody] = love.physics.newBody(world,fx,fy,0,10)
http://love2d.org/wiki/love.physics.newBody
You're setting the mass to 0.

disclaimer: I don't use love.physics much.
Socks
Prole
Posts: 14
Joined: Sat Dec 04, 2010 2:12 am

Re: love.physics causes C++ errors.

Post by Socks »

I fixed that, still nothing.
:p
Post Reply

Who is online

Users browsing this forum: No registered users and 4 guests