Hello @Cankar001,
Thank you for reaching out to us. You are doing here multiple things which are out of scope of support:
Using VS 2022 for an S24 project.
Using the std library in a Cinema 4D project.
The std library itself is generally out of scope of support.
I have therefore moved your posting. I would also recommend only posting code and debug outputs that are in English here, as I am the only one in SDK who can read German.
The 'no std library' rule stems more from the fact that we want truly compiler agnostic code rather than it inherently not working with Cinema 4D. Deep in our API there of is of course some std code, but it is mostly the Tech team writing that code and not the majority of our developers who write code without using the std library at all. I would recommend the same for you. Because it could be that we provide replacements for parts of the std library (which shadow it then) or just use symbols which shadow entities in std as we do not care.
I would remove the std::unordered_map<int, DebugRenderer*> mDebugRenderers; , as this is the only std code in that file. You can easily replace it with maxon::HashMap. This all reeks of 'you are mixing two versions of std' for me, because that is the only way how C3668 in std makes sense. Your errors also point to a C:\Program Files (x86)\Microsoft Visual Studio\2019\ while you claim to use VS 2022.
If that does not help, I would follow the AI advice given below.
Cheers,
Ferdinand
AI advice:
The errors you're seeing are related to the std::bad_cast and std::bad_typeid exceptions in C++. The errors indicate that the methods _Doraise with the override specifier did not override any base class methods, and the identifier _RAISE was not found.
This could be due to a few reasons:
You might be including the <typeinfo> header in a context where it's not supposed to be included, or it's being included indirectly through another header file.
There could be a conflict between different versions of the C++ standard library.
There might be a problem with your Visual Studio installation.
Without seeing the actual code, it's hard to provide a specific solution. However, here are some general steps you can take to troubleshoot:
Check your code for any unnecessary includes of <typeinfo>.
Make sure you're not mixing different versions of the C++ standard library.
Try to rebuild your project.
If none of the above work, consider reinstalling Visual Studio or repairing the installation.
Remember to always keep your software up-to-date to avoid such issues.
PS: Regarding the singleton/registration thing - You are also reinventing the wheel here the concepts of registries and published objects are very close to what you seem to want to do.
Finally, if you want a globally unique handler of something, you can also just use a UniqueRef to store it. Here is a small example of how you could do that (I wrote this 'blind' so it might not compile):
// my_declr.h
// Declare the globally unique render handler. UniqueRef realizes the singelton which stores a
// map of <int, DebugRenderer>. We wrap DebugRenderer in a WeakRawPtr so that we do not
// have to deal with possibly deleted objects.
extern maxon::UniqueRef<maxon::HashMap<Int32, maxon::WeakRawPtr<DebugRenderer>> g_render_handler;
// somefile.cpp/somefile.h
// Somewhere in our code we then actually pull the object up. I am using here an
// MAXON_INITIALIZATION macro so that the code runs when Cinema 4D is initialized.
maxon::UniqueRef<maxon::HashMap<Int32, maxon::WeakRawPtr<DebugRenderer>> g_render_handler;
MAXON_INITIALIZATION(
// Boot
[]() -> maxon::Result<void>
{
iferr_scope;
g_render_handler = maxon::UniqueRef<
maxon::HashMap<Int32, maxon::WeakRawPtr<DebugRenderer>>::Create() iferr_return;
return maxon::OK;
},
// Teardown
[]() -> void
{
g_render_handler = nullptr;
});
// Now we can use the g_render_handler in this manner:
// Get a renderer for a given command ID.
Result<DebugRenderer*> Get(Int32 id)
{
iferr_scope;
// Try to get an entry ...
const maxon::WeakRawPtr<DebugRenderer>* const item = g_render_handler->FindValue(id);
if (!item)
return maxon::UnexpectedError(
MAXON_SOURCE_LOCATION, "Could not find the renderer with id @1."_s, id);
// Unpack the WeakRawPtr to make sure the object is still alive.
DebugRenderer* const renderer = item->Get();
if (!renderer)
return maxon::UnexpectedError(
MAXON_SOURCE_LOCATION, "The renderer with id @1 is no longer alive."_s, id);
return renderer;
}
// Try to add a renderer to a given command ID slot.
Result<void> Set(Int32 id, DebugRenderer* renderer)
{
iferr_scope;
// Make sure the spot is still open.
const maxon::WeakRawPtr<DebugRenderer>* const item = g_render_handler->FindValue(id);
if (item)
return maxon::UnexpectedError(
MAXON_SOURCE_LOCATION, "An renderer with id @1 already exists."_s, id);
// Set the renderer.
maxon::WeakRawPtr<DebugRenderer> weakPtr (renderer);
g_render_handler->Insert(id, weakPtr) iferr_return;
return maxon::OK;
}