Added reset of the State::CurrentVertexArrayState() to prevent the State::_vas becoming a dangling pointer when VertexArrayState objects are deleted.
This commit is contained in:
parent
6455159757
commit
488b4854b2
@ -549,6 +549,9 @@ class OSG_EXPORT State : public Referenced
|
||||
/** Set the getCurrentVertexArrayState to the GlobalVertexArrayState.*/
|
||||
void setCurrentToGlobalVertexArrayState() { _vas = _globalVertexArrayState.get(); }
|
||||
|
||||
/** Reset the CurrentVertexArrayObject if it's value equals the specificied vas - use when deleting a vas.*/
|
||||
void resetCurrentVertexArrayStateOnMatch(VertexArrayState* vas) { if (_vas==vas) _vas = 0; }
|
||||
|
||||
|
||||
/** disable the vertex, normal, color, tex coords, secondary color, fog coord and index arrays.*/
|
||||
void disableAllVertexArrays();
|
||||
|
@ -182,10 +182,12 @@ class OSG_EXPORT VertexArrayState : public osg::Referenced
|
||||
|
||||
public:
|
||||
|
||||
virtual ~VertexArrayState();
|
||||
|
||||
// osg::GLBufferObject* getGLBufferObject(osg::Array* array);
|
||||
|
||||
osg::State* _state;
|
||||
osg::ref_ptr<ObserverSet> _stateObserverSet;
|
||||
osg::ref_ptr<osg::GLExtensions> _ext;
|
||||
|
||||
bool _isVertexBufferObjectSupported;
|
||||
|
@ -488,7 +488,7 @@ struct VertexAttribArrayDispatch : public VertexArrayState::ArrayDispatch
|
||||
virtual void enable_and_dispatch(osg::State& state, GLint size, GLenum type, GLsizei stride, const GLvoid *ptr, GLboolean normalized)
|
||||
{
|
||||
GLExtensions* ext = state.get<GLExtensions>();
|
||||
|
||||
|
||||
ext->glEnableVertexAttribArray( unit );
|
||||
ext->glVertexAttribPointer(static_cast<GLuint>(unit), size, type, normalized, stride, ptr);
|
||||
}
|
||||
@ -526,10 +526,19 @@ VertexArrayState::VertexArrayState(osg::State* state):
|
||||
_currentEBO(0),
|
||||
_requiresSetArrays(true)
|
||||
{
|
||||
_stateObserverSet = _state->getOrCreateObserverSet();
|
||||
_ext = _state->get<GLExtensions>();
|
||||
_isVertexBufferObjectSupported = _ext->isBufferObjectSupported;
|
||||
}
|
||||
|
||||
VertexArrayState::~VertexArrayState()
|
||||
{
|
||||
if (_stateObserverSet->getObserverdObject())
|
||||
{
|
||||
_state->resetCurrentVertexArrayStateOnMatch(this);
|
||||
}
|
||||
}
|
||||
|
||||
void VertexArrayState::generateVertexArrayObject()
|
||||
{
|
||||
_ext->glGenVertexArrays(1, &_vertexArrayObject);
|
||||
@ -539,7 +548,7 @@ void VertexArrayState::deleteVertexArrayObject()
|
||||
{
|
||||
if (_vertexArrayObject)
|
||||
{
|
||||
VAS_NOTICE<<" VertexArrayState::deleteVertexArrayObject() "<<_vertexArrayObject<<std::endl;
|
||||
VAS_NOTICE<<" VertexArrayState::deleteVertexArrayObject() "<<_vertexArrayObject<<" "<<_stateObserverSet->getObserverdObject()<<std::endl;
|
||||
|
||||
_ext->glDeleteVertexArrays(1, &_vertexArrayObject);
|
||||
_vertexArrayObject = 0;
|
||||
|
Loading…
Reference in New Issue
Block a user