Page 1 of 1

HSPlasma returning empty vectors

PostPosted: Wed Mar 21, 2018 4:43 pm
by Sirius
Hello everyone,

I'm currently using HSPlasma in a C++ project, which needs to process PRPs fast (Python is not an option). You probably know what I'm talking about ;)

So I compiled my own version of HSPlasma (finally!), dynamically linked to it in my other VS project, DLL loads correctly, etc (standard stuff so far). However, there is an annoying error I'm running in, and I can't nail down what's causing it.

It seems anytime HSPlasma exposes a class property of type std::vector<class or value type> (though a getter or a public property), accessing it is impossible. Instead I retrieve some other empty vector - even when it should be returned by reference... This is very annoying for methods like plSceneNode.getSceneObjects(), or plDIInterface.fIndices. I don't think I messed up the syntax either...
Code: Select all
sceneNode->getSceneObjects().size(); // returns 0

As a workaround, I added two more methods directly inside HSPlasma's plSceneNode class:
Code: Select all
plKey& plSceneNode::getSceneObject(int id) { return fSceneObjects[id]; }
size_t plSceneNode::getSceneObjectsSize() { return fSceneObjects.size(); }

Those methods CAN access the content of the std::vector, and allow me to retrieve the objects inside the scene node. However, having to add hack functions all over HSPlasma is obviously very annoying and not desirable.

Is there something I'm missing ?

Re: HSPlasma returning empty vectors

PostPosted: Fri Mar 23, 2018 6:56 pm
by Zrax
Hmm, I certainly haven't seen that type of behavior before in, for example, PlasmaShop (which does use those same interfaces). My first guess since the code directly exposes the `std::vector` is that you might be mixing Release libhsplasma with a Debug client application or vice versa. MSVC unfortunately uses different (non-ABI compatible) versions of many parts of STL between Debug and Release, and causes all sorts of confusing and hard to debug problems in doing so... libhsplasma makes no attempt to shield you from this, so it is important to have both a Devel and Release build if you plan on building both in the client.

Re: HSPlasma returning empty vectors

PostPosted: Sat Mar 24, 2018 7:19 am
by Sirius
That was it :) My program was set as Debug, while HSPlasma was compiled as Release since I figured I wouldn't need to debug that part of the code. Didn't know it would change the behavior for exposed methods.
Thanks a lot :D