-
-
Notifications
You must be signed in to change notification settings - Fork 21.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Initialize variables in servers/physics #52668
Initialize variables in servers/physics #52668
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you! I've double checked initialized values and left some comments about missing ones.
servers/physics_3d/shape_3d_sw.cpp
Outdated
custom_bias = 0; | ||
configured = false; | ||
} | ||
Shape3DSW::Shape3DSW() {} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Empty constructors could be removed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was only able to move empty constructors to .h files, because probably due virtual destructors, build fails when completely removing default constructor.
405a8e1
to
ab26323
Compare
BroadPhase2DBVH::BroadPhase2DBVH() { | ||
bvh.set_pair_callback(_pair_callback, this); | ||
bvh.set_unpair_callback(_unpair_callback, this); | ||
pair_callback = nullptr; | ||
pair_userdata = nullptr; | ||
unpair_userdata = nullptr; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This might be worth reviewing @pouleyKetchoupp @lawnjelly as the previous code seems a bit weird. We set callbacks in the bvh
manager before setting only the pair_callback
to nullptr
and leaving unpair_callback
uninitialized.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually this is fine but the code is hard to read :)
It's just that there's _pair_callback
(with underscore) passed to the bvh and pair_callback
(without) which is initialized to nullptr.
unpair_callback
was uninitialized though, so it's all good now.
@@ -163,7 +163,7 @@ class JacobianEntry3DSW { | |||
Vector3 m_0MinvJt; | |||
Vector3 m_1MinvJt; | |||
//Optimization: can be stored in the w/last component of one of the vectors | |||
real_t m_Adiag; | |||
real_t m_Adiag = 1.0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems to have a fail condition if it's <= 0.0
, maybe the default should be 0.0
as uninitialized state?
servers/physics_3d/joints/jacobian_entry_3d_sw.h
73: m_Adiag = massInvA + m_0MinvJt.dot(m_aJ) + massInvB + m_1MinvJt.dot(m_bJ);
75: ERR_FAIL_COND(m_Adiag <= real_t(0.0));
89: m_Adiag = m_0MinvJt.dot(m_aJ) + m_1MinvJt.dot(m_bJ);
91: ERR_FAIL_COND(m_Adiag <= real_t(0.0));
104: m_Adiag = m_0MinvJt.dot(m_aJ) + m_1MinvJt.dot(m_bJ);
106: ERR_FAIL_COND(m_Adiag <= real_t(0.0));
121: m_Adiag = massInvA + m_0MinvJt.dot(m_aJ);
123: ERR_FAIL_COND(m_Adiag <= real_t(0.0));
126: real_t getDiagonal() const { return m_Adiag; }
166: real_t m_Adiag;
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah it would be good to check uninitialized cases, but we would also need a check in getDiagonal()
to catch these cases (debug only to avoid potential performance hits in release), something like:
real_t getDiagonal() const
{
#ifdef DEBUG_ENABLED
ERR_FAIL_COND_V(m_Adiag <= real_t(0.0), m_Adiag);
#endif
return m_Adiag;
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Might be worth doing in a separate PR not to grow the scope of this one too much I guess.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewed everything, looks great aside from the few comments I left. Should be mergeable once resolved.
ab26323
to
be048f6
Compare
be048f6
to
5cee6ea
Compare
5cee6ea
to
91257c3
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great!
Part of #43636