lovebrew / lovepotion

LÖVE for Nintendo Homebrew
https://lovebrew.org
Other
546 stars 42 forks source link

[Bug]: Fixture:getShape() returns a fixture #188

Closed Nawias closed 1 year ago

Nawias commented 1 year ago

Software Version

2.4.x (latest compiled after quad fix)

What Happened?

As in title, Fixture:getShape() returns a fixture.

What was Expected?

Fixture:getShape() should return Shape associated with the fixture.

Code to Reproduce

local function testFixture()
  local world = love.physics.newWorld(0,0)
  local body = love.physics.newBody(world,0,0,"static")
  local shape = love.physics.newRectangleShape(10,10)
  local fixture = love.physics.newFixture(body,shape,0,5)
  if fixture:getShape():type() == "Fixture" then 
    error("Shape was fixture, should be PolygonShape!")
  end
  fixture:release()
  shape:release()
  body:release()
  world:destroy()
end

function love.load()
  testFixture()
end

Console

Nintendo 3DS

Firmware Version(s)

11.16.0-49E

Custom Firmware Version

11.0

Execution Method

Homebrew Menu

Code of Conduct

Nawias commented 1 year ago

https://github.com/lovebrew/lovepotion/blob/a52d821d9afed40654da1e9a3289ec55edbbe511/source/objects/box2d/fixture/wrap_fixture.cpp#L118-L141

I don't know if I'm reading this right, but it seems to me that Fixture->shape is not pushed to lua if its any of the types: EdgeShape, ChainShape,CircleShape and PolygonShape - but these all should be usable shapes. As to why it would return a fixture - I have no idea.

TurtleP commented 1 year ago

It's not pushing a fixture. However, it is only pushing the base Shape class. I must have overlooked this on accident, as this module was a major pain to do. I think all that would need to be done is casting the shape accordingly to its type and pushing it to lua.

Nawias commented 1 year ago

But if that was the case, then Fixture:getShape():type() would return 'Shape', not 'Fixture', right?

TurtleP commented 1 year ago

Hm, that might also be an oversight on my part. I'll have to check if I accidentally copypasta'd the Type from Fixture to Shape - or registering Shape accidentally uses the wrong Type.

Nawias commented 1 year ago

Your fix in commit ddaa3 did the job, all is good now.