SayGoodBye not being called inside world->DestroyJoint.

Greetings,

In world->DestroyJoint no call is being made to SayGoodbye. For proper cleanup, I think all joints being destroyed should probably call SayGoodbye to allow the program to do proper cleanup.

Or am I missing something?

Regards,
Q

PS(I should mention that it appears that when a BODY is destroyed it IS successfully destroying each joint it is connected to as well as calling SayGodbye for each of those destroyed joints. This appears to only be an issue with world->DestroyJoint).
No need in this case. The client knows they are destroying the joint. The purpose of the destruction listener is to inform the client about implicit destruction.
Erin,

Shouldn't the interface be consistent so that developers have one method-type where they can rely on being made aware of any world body/structure destruction, regardless of it's cause? Just like with bodies/fixtures, SayGoodbye is a fantastic place to do any final checks/notifications/cleanup. Not only that, it is also a great place to do sanity checks and to debug unexpected destruction situations. But those advantages only work if it is called consistently and reliably regardless of the initial source of destruction.

Not to put to fine a point on it, but to quote your own words: "The intent of the SayGoodbye function is to let you nullify any references to the fixture that is being destroyed. This more important with joints, which have less clear ownership" (From post: viewtopic.php?f=4&t=4886)

It is also worth noting that the manual does not make and distinction between implicit and explicit destruction when describing the SayGoodbye functions. So regardless of if this is changed, the manual should probably be clarified.

I realize that you may have no intention of making any changes to this behavior, but my (humble) suggestion to modify the behaviour so the SayGoodbye methods look and work like the following:

Code:
void BQDestructListener::SayGoodbye(b2Joint* joint, bool dueToBodyDestruction);
void BQDestructListener::SayGoodbye(b2Fixture* fixture, bool dueToBodyDestruction);

and even this would be quite useful:
Code:
void BQDestructListener::SayGoodbye(b2Body* body);

(Not the best param name, but you get the idea 😉 )

This way, regardless of the cause of destruction there is one central point where developers can do checks/debugging/etc. By passing the dueToBodyDestruction it will allow the developer to the scope of the destruction.... also, the SayGoodbye for the body is useful since it is actually possible to have a body exist without any fixtures...even if just by accident. Also sayGoodbye for the body would be a great addition since userdata is often attached to the body rather than the fixture (and therefore should not be released until the body is going to be destroyed).

Anyway, it's all just one person's opinion, but since userdata can be attached to any/all of these, knowing when each one is destroyed would greatly simplify coding and cleanup (and debugging) for them all.

Regards,
Q
You are trying to make the interface into something it isn't and then calling it inconsistent. I don't want users to feel they need to implement some extensive callback system to get anything done. I'm trying to follow the policy of keeping Box2D as simple as possible, but not simpler.

If you are explicitly destroying a joint, then ownership is clear. If you destroy a body and the joint is implicitly destroyed, then ownership is not clear. I want to solve the problem where ownership is unclear. I could just let the joint dangle and be inactive, but this is inefficient and usually not desired and may lead to leaks. Also, many times in client code you would like to create-and-forget. So implicit destruction is a nice convenience.

Now take your case where you like the callback system. You could always explicitly call your own callback when you explicitly destroy a joint. This will let you keep some cleanup code centralized.
Erin,

Just a note: I updated my post above while you were replying.

In anycase, I understand what you are saying, but I really think that implementing SayGoodbye callbacks for each of these would make a developers code simpler, not more complex.

Also, I don't think it would be any more *required* than it is already. Developers can choose to implement the callbacks if they are interested in doing something at that point, or they could skip it if they are not. I don't see that making it more robust makes it any more required.

However, I understand that this is not something you are planning to change. That's cool, "Great minds don't always think alike" 😉

In any case, I think the manual should probably get updated to reflect the implicit vs explicit reasons for getting (or not getting, as the case may be) a SayGoodBye call.

Anyway, as always, great job on this terrific engine. You efforts are much appreciated.

Best Regards,
Q

PS(BTW, Great idea about calling my own callback...I never even considered that.)
I added a note about explicit destruction to the manual. Thanks.

Original thread: https://box2d.org/forum/viewtopic.php?t=4892