Legacy Code still a thing?
-
Hi.
I just tried to compile a simple plugin for 2024 whose code basically worked for the last 16 years. Now it throws 40 errors.
Has the time come for an inevitable re-write or should it continue to work and it's just a matter of fixing some stuff?
Cheers
-
Hello @Yakuza,
Thank you for reaching out to us. 'Rewrite' is a bit too strong word, but the 2024 release comes with significant changes to the API to achieve the speed improvements it does. You can read about the details in the Migrating Plugins to the 2024.0 API guide.
Cheers,
Ferdinand -
Thanks Ferdinand, I'll try.
-
Hey @Yakuza,
It is usually not that bad, things look more complicated than they are. Just ask questions here on Plugin Café when you are stuck on an error, I will nudge you then into the right direction. After a few items you will get the hang of it.
40 errors should be fixable in a few hours at most, including the learning curve.
Cheers,
Ferdinand -
Thank you. It's actually "only" 26 errors on compilation. They are mostly BaseContainer related, to no surprise, since the plugin does largely only handle containers and their values. See console output below.
So if you for starters could nudge me regarding
cannot convert from 'const BaseContainer * to 'BaseContainer* and
cannot convert 'this' pointer from 'const BaseContainer' to 'BaseContainer &
I might be half way done.Error1 - Lines 51ff look like this
Int32 SOLO::GetState(BaseDocument *doc, GeDialog* parentManager) { BaseContainer *bc = doc->GetDataInstance()->GetContainerInstance(SOLO_ID); if (!bc) return CMD_ENABLED; else if (bc->GetInt32(ID_SOLO_SET, 0) == 0) return CMD_ENABLED; else return CMD_ENABLED | CMD_VALUE; }
Error3 - Line 181
obj->GetDataInstance()->GetContainerInstance(SOLO_ID)->SetInt32(ID_SOLO_STATE, data);
Any pointers to pointers and constant containers would be welcome.
Cheers,
Bo
Severity Code Description Project File Line Suppression State
Error C2440 'initializing': cannot convert from 'const BaseContainer *' to 'BaseContainer *' solo2023 D:\MAXON_CODE\C4D_2024_2_CODE\sdk\plugins\solo2023\source\solo2023.cpp 53
Error C4996 'BaseList2D::GetData': Use GetDataInstanceRef() to avoid the unnecessary BaseContainer copy solo2023 D:\MAXON_CODE\C4D_2024_2_CODE\sdk\plugins\solo2023\source\solo2023.cpp 109
Error C2662 'void BaseContainer::SetInt32(Int32,Int32)': cannot convert 'this' pointer from 'const BaseContainer' to 'BaseContainer &' solo2023 D:\MAXON_CODE\C4D_2024_2_CODE\sdk\plugins\solo2023\source\solo2023.cpp 181
Error C2662 'void BaseContainer::SetInt32(Int32,Int32)': cannot convert 'this' pointer from 'const BaseContainer' to 'BaseContainer &' solo2023 D:\MAXON_CODE\C4D_2024_2_CODE\sdk\plugins\solo2023\source\solo2023.cpp 182
Error C2662 'void BaseContainer::SetBool(Int32,Bool)': cannot convert 'this' pointer from 'const BaseContainer' to 'BaseContainer &' solo2023 D:\MAXON_CODE\C4D_2024_2_CODE\sdk\plugins\solo2023\source\solo2023.cpp 183
Error C4263 'Bool SoloPrefs::Init(GeListNode *)': member function does not override any base class virtual member function solo2023 D:\MAXON_CODE\C4D_2024_2_CODE\sdk\plugins\solo2023\source\SoloPrefs.cpp 133
Error C2662 'void BaseContainer::SetInt32(Int32,Int32)': cannot convert 'this' pointer from 'const BaseContainer' to 'BaseContainer &' solo2023 D:\MAXON_CODE\C4D_2024_2_CODE\sdk\plugins\solo2023\source\solo2023.cpp 199
Error C4264 'Bool NodeData::Init(GeListNode *,Bool)': no override available for virtual member function from base 'NodeData'; function is hidden solo2023 D:\MAXON_CODE\C4D_2024_2_CODE\sdk\plugins\solo2023\source\SoloPrefs.cpp 145
Error C4263 'Bool SoloPrefs::GetDParameter(GeListNode *,const DescID &,GeData &,DESCFLAGS_GET &)': member function does not override any base class virtual member function solo2023 D:\MAXON_CODE\C4D_2024_2_CODE\sdk\plugins\solo2023\source\SoloPrefs.cpp 134
Error C2662 'void BaseContainer::SetInt32(Int32,Int32)': cannot convert 'this' pointer from 'const BaseContainer' to 'BaseContainer &' solo2023 D:\MAXON_CODE\C4D_2024_2_CODE\sdk\plugins\solo2023\source\solo2023.cpp 200
Error C4264 'Bool NodeData::GetDParameter(const GeListNode *,const DescID &,GeData &,DESCFLAGS_GET &) const': no override available for virtual member function from base 'NodeData'; function is hidden solo2023 D:\MAXON_CODE\C4D_2024_2_CODE\sdk\plugins\solo2023\source\SoloPrefs.cpp 145
Error C4263 'Bool SoloPrefs::GetDEnabling(GeListNode *,const DescID &,const GeData &,DESCFLAGS_ENABLE,const BaseContainer *)': member function does not override any base class virtual member function solo2023 D:\MAXON_CODE\C4D_2024_2_CODE\sdk\plugins\solo2023\source\SoloPrefs.cpp 136
Error C2662 'void BaseContainer::SetBool(Int32,Bool)': cannot convert 'this' pointer from 'const BaseContainer' to 'BaseContainer &' solo2023 D:\MAXON_CODE\C4D_2024_2_CODE\sdk\plugins\solo2023\source\solo2023.cpp 201
Error C4264 'Bool NodeData::GetDEnabling(const GeListNode *,const DescID &,const GeData &,DESCFLAGS_ENABLE,const BaseContainer *) const': no override available for virtual member function from base 'NodeData'; function is hidden solo2023 D:\MAXON_CODE\C4D_2024_2_CODE\sdk\plugins\solo2023\source\SoloPrefs.cpp 145
Error C4263 'Bool SoloPrefs::GetDDescription(GeListNode *,Description *,DESCFLAGS_DESC &)': member function does not override any base class virtual member function solo2023 D:\MAXON_CODE\C4D_2024_2_CODE\sdk\plugins\solo2023\source\SoloPrefs.cpp 137
Error C2662 'void BaseContainer::SetInt32(Int32,Int32)': cannot convert 'this' pointer from 'const BaseContainer' to 'BaseContainer &' solo2023 D:\MAXON_CODE\C4D_2024_2_CODE\sdk\plugins\solo2023\source\solo2023.cpp 208
Error C4264 'Bool NodeData::GetDDescription(const GeListNode *,Description *,DESCFLAGS_DESC &) const': no override available for virtual member function from base 'NodeData'; function is hidden solo2023 D:\MAXON_CODE\C4D_2024_2_CODE\sdk\plugins\solo2023\source\SoloPrefs.cpp 145
Error C2662 'void BaseContainer::SetInt32(Int32,Int32)': cannot convert 'this' pointer from 'const BaseContainer' to 'BaseContainer &' solo2023 D:\MAXON_CODE\C4D_2024_2_CODE\sdk\plugins\solo2023\source\solo2023.cpp 209
Error C2662 'void BaseContainer::SetBool(Int32,Bool)': cannot convert 'this' pointer from 'const BaseContainer' to 'BaseContainer &' solo2023 D:\MAXON_CODE\C4D_2024_2_CODE\sdk\plugins\solo2023\source\solo2023.cpp 210
Error C2440 'initializing': cannot convert from 'const BaseContainer *' to 'BaseContainer *' solo2023 D:\MAXON_CODE\C4D_2024_2_CODE\sdk\plugins\solo2023\source\solo2023.cpp 228
Error C2662 'void BaseContainer::SetInt32(Int32,Int32)': cannot convert 'this' pointer from 'const BaseContainer' to 'BaseContainer &' solo2023 D:\MAXON_CODE\C4D_2024_2_CODE\sdk\plugins\solo2023\source\solo2023.cpp 260
Error C2664 'Bool SoloPrefs::InitValues(const DescID &,Description *)': cannot convert argument 1 from '<unnamed-enum-PREF_SOLOPREFS_MAIN_GROUP>' to 'const DescID &' solo2023 D:\MAXON_CODE\C4D_2024_2_CODE\sdk\plugins\solo2023\source\SoloPrefs.cpp 209
Error C2440 '<function-style-cast>': cannot convert from 'initializer list' to 'GeData' solo2023 D:\MAXON_CODE\C4D_2024_2_CODE\sdk\plugins\solo2023\source\SoloPrefs.cpp 229
Error C2664 'Bool SoloPrefs::InitValues(const DescID &,Description *)': cannot convert argument 1 from '<unnamed-enum-PREF_SOLOPREFS_MAIN_GROUP>' to 'const DescID &' solo2023 D:\MAXON_CODE\C4D_2024_2_CODE\sdk\plugins\solo2023\source\SoloPrefs.cpp 271
Error C2440 'initializing': cannot convert from 'const BaseContainer *' to 'BaseContainer *' solo2023 D:\MAXON_CODE\C4D_2024_2_CODE\sdk\plugins\solo2023\source\SoloPrefs.cpp 278
Error C2440 '=': cannot convert from 'const BaseContainer *' to 'BaseContainer *' solo2023 D:\MAXON_CODE\C4D_2024_2_CODE\sdk\plugins\solo2023\source\SoloPrefs.cpp 282 -
Hey @Yakuza,
changes to the mutability, a.k.a.,
const
-ness, of data are the overarching theme of the 2024 changes, if you haven't done it already, I would strongly recommend reading the migration guide. It is split into bite sized chunks so that you only must consume what you need, in this case the most relevant chunk is probably Node Data Container Access.For your error, you should try (the const-ness of the pointer is optional) this, since you only want to read here:
const BaseContainer* const bc = doc->GetDataInstance()->GetContainerInstance(SOLO_ID);
Cheers,
Ferdinand -
Thank you, Ferdinand. Yes, I did that already and changed the first bc to const. Your link says btw.:
" Note -Legacy code will compile and run without adaptions but adhering to these changes will yield performance improvements."Now there are 10 instances of error 3 above.
-
Hello @Yakuza,
The note is referring to the
BaseList2D
data container access methods where 2023 code will indeed compile for 2024. Regarding the rest of your errors, it is a bit hard to infer what is happening in each of them without your code, but I would split them into two groups (there are also other error types in there):const-ness Violations
E.g.:
Error C2662 'void BaseContainer::SetInt32(Int32,Int32)': cannot convert 'this' pointer from 'const BaseContainer' to 'BaseContainer &' solo2023 ...\solo2023.cpp 181
You are trying here to call
::SetInt32
on aconst BaseContainer
. This cannot work, as your container is immutable andSetInt32
is not aconst
member function. You must retrieve the mutable container. Note that this is not always possible now. When you get passed in aconst BaseList2D*
you cannot access its writeable data container. When the node is const, you can only callconst
methods on the node, and all methods which return writeable data are non-const in 2024. You can cast away the const-ness of things if you really want to, but you risk crashing with that because things areconst
so that they can be accessed in parallel. The migration guide has a whole section on what to do in such cases.In case you are a bit fuzzy on the concept of
const
-correctness in general orconst
-member functions in particular, these resources might help:- Iso Cpp - Const Correctness: The official explanation for the concept of const correctness. As common for the C++ Foundation, the official explanation is a bit convoluted and overly complicated (at least for my taste).
- MSVC - const: Microsofts take on this is much user friendly, especially the section on
const
member functions/methods is much better IMHO.
NodeData Signature Changes
E.g.:
Error C4264 'Bool NodeData::Init(GeListNode *,Bool)': no override available for virtual member function from base 'NodeData'; function is hidden solo2023 ...\SoloPrefs.cpp 145
or:
Error C4263 'Bool SoloPrefs::GetDParameter(GeListNode *,const DescID &,GeData &,DESCFLAGS_GET &)': member function does not override any base class virtual member function solo2023 ...\SoloPrefs.cpp 134
Many
NodeData
methods and methods ofNodeData
derived interfaces have changed their signature.NodeData::Init
has for example now a second argumentBool isCloneInit
and NodeData::GetDParameter is now aconst
method and the first argumentnode
is now alsoconst
; this is an example where you could not retrieve a writeable data container fornode
anymore since you are not supposed to write to the node in this method since it is now acost
method.Cheers,
Ferdinand -
@ferdinand
Thank you very much. I don't get a lot of that but was able to change the flow/logic of the plugin so that the compiler doesn't throw any errors anymore (but a bazillion warnings ). I have no idea if this will work because I still cannot test it since actually it's two plugins, the command plugin and its preferences dialog. The latter is unfortunately larger than the command itself and still throws 21 errors.They all occur in PrefsDialogObject class. Do you have any ideas on these?
Severity Code Description Project File Line Suppression State Error C4263 'Bool SoloPrefs::Init(GeListNode *)': member function does not override any base class virtual member function solo2023 D:\MAXON_CODE\C4D_2024_2_CODE\sdk\plugins\solo2023\source\SoloPrefs.cpp 134 Error C4264 'Bool NodeData::Init(GeListNode *,Bool)': no override available for virtual member function from base 'NodeData'; function is hidden solo2023 D:\MAXON_CODE\C4D_2024_2_CODE\sdk\plugins\solo2023\source\SoloPrefs.cpp 146 Error C4263 'Bool SoloPrefs::GetDParameter(GeListNode *,const DescID &,GeData &,DESCFLAGS_GET &)': member function does not override any base class virtual member function solo2023 D:\MAXON_CODE\C4D_2024_2_CODE\sdk\plugins\solo2023\source\SoloPrefs.cpp 135 Error C4264 'Bool NodeData::GetDParameter(const GeListNode *,const DescID &,GeData &,DESCFLAGS_GET &) const': no override available for virtual member function from base 'NodeData'; function is hidden solo2023 D:\MAXON_CODE\C4D_2024_2_CODE\sdk\plugins\solo2023\source\SoloPrefs.cpp 146 Error C4263 'Bool SoloPrefs::GetDEnabling(GeListNode *,const DescID &,const GeData &,DESCFLAGS_ENABLE,const BaseContainer *)': member function does not override any base class virtual member function solo2023 D:\MAXON_CODE\C4D_2024_2_CODE\sdk\plugins\solo2023\source\SoloPrefs.cpp 137 Error C4264 'Bool NodeData::GetDEnabling(const GeListNode *,const DescID &,const GeData &,DESCFLAGS_ENABLE,const BaseContainer *) const': no override available for virtual member function from base 'NodeData'; function is hidden solo2023 D:\MAXON_CODE\C4D_2024_2_CODE\sdk\plugins\solo2023\source\SoloPrefs.cpp 146 Error C4263 'Bool SoloPrefs::GetDDescription(GeListNode *,Description *,DESCFLAGS_DESC &)': member function does not override any base class virtual member function solo2023 D:\MAXON_CODE\C4D_2024_2_CODE\sdk\plugins\solo2023\source\SoloPrefs.cpp 138 Error C4264 'Bool NodeData::GetDDescription(const GeListNode *,Description *,DESCFLAGS_DESC &) const': no override available for virtual member function from base 'NodeData'; function is hidden solo2023 D:\MAXON_CODE\C4D_2024_2_CODE\sdk\plugins\solo2023\source\SoloPrefs.cpp 146 Error C2664 'Bool SoloPrefs::InitValues(const DescID &,Description *)': cannot convert argument 1 from '<unnamed-enum-PREF_SOLOPREFS_MAIN_GROUP>' to 'const DescID &' solo2023 D:\MAXON_CODE\C4D_2024_2_CODE\sdk\plugins\solo2023\source\SoloPrefs.cpp 210 Error C2440 '<function-style-cast>': cannot convert from 'initializer list' to 'GeData' solo2023 D:\MAXON_CODE\C4D_2024_2_CODE\sdk\plugins\solo2023\source\SoloPrefs.cpp 230 Error C2664 'Bool SoloPrefs::InitValues(const DescID &,Description *)': cannot convert argument 1 from '<unnamed-enum-PREF_SOLOPREFS_MAIN_GROUP>' to 'const DescID &' solo2023 D:\MAXON_CODE\C4D_2024_2_CODE\sdk\plugins\solo2023\source\SoloPrefs.cpp 272 Error C2440 'return': cannot convert from 'const BaseContainer *' to 'BaseContainer *' solo2023 D:\MAXON_CODE\C4D_2024_2_CODE\sdk\plugins\solo2023\source\SoloPrefs.cpp 287
-
Hey @Yakuza,
these are the exact same errors I explained above.
// 2023 and earlier NodeData::Init Bool SoloPrefs::Init(GeListNode* node) // 2024 and later NodeData::Init Bool SoloPrefs::Init(GeListNode* node, Bool isCloneInit)
// 2023 and earlier NodeData::GetDParameter Bool SoloPrefs::GetDParameter(GeListNode* node, const DescID& id, GeData& t_data, DESCFLAGS_GET& flags) // 2024 and later NodeData::GetDParameter Bool SoloPrefs::GetDParameter(const GeListNode *node, const DescID &id, GeData &t_data, DESCFLAGS_GET &flags) const
When you then try to declare a virtual function on your
SoloPrefs
, the compiler complains because you are trying to declare a function which does not exist anymore on the base class (PrefsDialogObject
I assume) you are overriding.Cheers,
Ferdinand -
Oh sorry, thank you. I totally missed that.