Setting up global plugin structs
-
Hi folks,
I've had a persistent issue with setting up some plugins with global structs. I'm sure I've read about this previously, maybe something to do with symbols not being loaded before PluginStart() is called? I forget the details...
Anyhow, is there a 'correct' way to setup a global struct for my plugin, that has BaseContainers, Strings etc in it? Take this for example, if I do this:
// global struct struct MyStruct { BaseContainer bc; }mystruct;
the plugin fails to start and I get a crash file with nothing in it. If I do this:
// global struct struct MyStruct { std::vector< BaseContainer > bc; }mystruct;
then the plugin loads. Obviously I have to take care of the array, but that aside. Is there a way of having a global struct load with Cinema objects, without cheating it like this? Or - is there a better cheat...
WP.
-
hi,
after you struct declaration, you are adding mystruct witch will create a variable of the type of your structure.
It try to allocate a BaseContainer that is unknown.If you add that to a Vector, as the vector is empty, it doesn't try to allocate a BaseContainer.
I'm not sure why you need a global structure, but I would create a pointer and in pluginstart and pluginend take care of assign memory and free it.
// global struct struct MyStruct { BaseContainer bc; } MyStruct *g_mystruct = nullptr;
You can have a look at Entity Creation in our documentation.
Cheers,
Manuel -
Hi Manuel,
what you say rings a bell. I was sure it was because the vector hadn't allocated anything yet.
Global possibly wasn't the best way admittedly, it just started like that for convenience. But it ended up being a bit complex, there's a lot of things accessing it, so I didn't want to change it (for now).
@m_magalhaes said in Setting up global plugin structs:
create a pointer and in pluginstart and pluginend take care of assign memory and free it
hadn't thought of that. Seems to work - I'll go with that! Thanks
WP.