erincatto / box2d

Box2D is a 2D physics engine for games
https://box2d.org
MIT License
8.09k stars 1.52k forks source link

Recent userdata changes are not backwards-compatible #663

Closed flarn2006 closed 3 years ago

flarn2006 commented 3 years ago

Setting b2BodyDef::userData directly to a void* pointer, and using b2Body::SetUserData(void*), both worked in version 2.4.0 of the library. Now that that's been changed, code that was written for the older versions will no longer compile and/or link. Sometimes it's necessary to break backwards compatibility, of course, but ideally it should be avoided where possible, and it seems unlikely that this is the best option here.

erincatto commented 3 years ago

Do you have a suggestion on how to offer the new feature for user data without breaking compatibility? Also fixing this in user code is likely to take about 5 minutes.

thegrb93 commented 3 years ago

@erincatto this way seems more backwards compatible. https://github.com/erincatto/box2d/pull/635

flarn2006 commented 3 years ago

Yes, I know, but it might not be as trivial for someone who's compiling someone else's inactive project but doesn't really know C++ themselves.

As for how I'd suggest doing it, I'm not entirely sure what the goal is, or how it all works under the hood, but I'd suggest, first off, re-adding the SetUserData(void*) functions. Then, maybe define b2BodyUserData::b2BodyUserData(void*) and b2BodyUserData::operator void*() to do the appropriate conversions, along with the same for b2FixtureUserData. Do you think that would be enough?

EDIT: This was in response to @erincatto, not thegrb93.

erincatto commented 3 years ago

Sorry, I don't think that will work when people define their own user data type.

Unfortunately I have to break compatibility sometimes to support new features. Sometimes people want conflicting things. In this case someone wanted strongly typed user data. This conflicts with your desire to not break the API.

I have found strongly typed user data to be useful, so I'm inclined to keep this feature.