spookyboo / HLMSEditor

High Level Material Shader editor
79 stars 25 forks source link

Stop returning referece to locally created Vector3/Quaternion #6

Closed Ybalrid closed 7 years ago

Ybalrid commented 7 years ago

In the "cameraman" code, position/orientation was returned as const ref to a localy created Vector3 or Quaternion object.

IIRC, in that case Visual Studio will create a copy of the object anyway, but GCC won't, and will only print out a warning while doing what the code is supposed to do.

That reference may be "dangling" and will not permit ot access the object.

Ogre::SceneNode::getPosition/Orientation returns by value anyway and modern C++ standard inforce Return Value Optimization.

This seems to be the cause of a segmentation fault when attempting to move the camera on the main viewport of the applciation if build with GCC on Linux.

Signed-off-by: Arthur Brainville (Ybalrid) ybalrid@ybalrid.info

Ybalrid commented 7 years ago

I just saw that the files say that these are generated from your magnus project (cool idea BTW, I'm currently messing with Qt GUI + Ogre and it's a PITA!).

I'm not looking into the details, but you should update magnus so that it doesn't generate methods that return references to temporary stack object. This may work fine with Visual Studio but cl.exe isn't the most "trustable" compiler ever :wink: