-
-
Notifications
You must be signed in to change notification settings - Fork 21.9k
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
Avoid const_cast
in mesh_storage.h
#94893
Avoid const_cast
in mesh_storage.h
#94893
Conversation
7300703
to
f04a9bb
Compare
Something fishy is happening here. From reading the code I would expect this would fail to compile because the definition of
The fact that you can just change the definition in |
#define FUNC1RC(m_r, m_type, m_arg1) \
virtual m_r m_type(m_arg1 p1) const override { \
if (Thread::get_caller_id() != server_thread) { \
m_r ret; \
command_queue.push_and_ret(server_name, &ServerName::m_type, p1, &ret); \
SYNC_DEBUG \
MAIN_THREAD_SYNC_CHECK \
return ret; \
} else { \
command_queue.flush_if_pending(); \
return server_name->m_type(p1); \
} \
} and i agree it doesnt make so much sense, but i dont see so much of a downside to the definitions not matching up, but |
Just my two cent... In cases where one wants getters to look like they are read-only from the surface, but there's a case that needs to update some internal cache in order to return results, one can decorate the data involved with |
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 fine to me.
Thank you for the clarification!
In this case it works out because nobody calls the function directly, it always goes through an intermediate layer. So from the user point of view they are calling a const function still. I agree with your suggestion in other cases though |
i would prefer it too, the reason i couldn't is because |
const_cast
in mesh_storage.h
Thanks! |
Avoids const_cast in mesh_storage.h by changing the virtual method
RendererMeshStorage::multimesh_get_aabb
to match the constness ofRendererMeshStorage::mesh_get_aabb
, which has to do similar dirty checksthis kind of const_cast can be very nasty as the compiler might be able to choose to return
aabb
before its changed by_update_dirty_multimeshes
(like in #93759)