DrawElementsFacade: use ref_ptr instead of mismatched new/free

Found by AddressSanitizer; not seen to crash, but probably best fixed
This commit is contained in:
Rebecca N. Palmer 2015-02-12 15:48:36 +00:00
parent 1bf0b7222d
commit 8c38f799ad

View File

@ -28,6 +28,7 @@
#include <osg/Geometry> #include <osg/Geometry>
#include <osg/PrimitiveSet> #include <osg/PrimitiveSet>
#include <osg/Texture2D> #include <osg/Texture2D>
#include <osg/ref_ptr>
#include <stdio.h> #include <stdio.h>
#include <simgear/math/sg_random.h> #include <simgear/math/sg_random.h>
@ -122,16 +123,16 @@ public:
osg::DrawElements* getDrawElements() osg::DrawElements* getDrawElements()
{ {
if (count > 65535) { if (count > 65535) {
free (_ushortElements); _ushortElements = 0;
return _uintElements; return _uintElements;
} else { } else {
free (_uintElements); _uintElements = 0;
return _ushortElements; return _ushortElements;
} }
} }
protected: protected:
osg::DrawElementsUShort* _ushortElements; osg::ref_ptr<osg::DrawElementsUShort> _ushortElements;
osg::DrawElementsUInt* _uintElements; osg::ref_ptr<osg::DrawElementsUInt> _uintElements;
unsigned count; unsigned count;
}; };