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:
Robert Osfield
2019-01-21 17:36:40 +00:00
parent 6455159757
commit 488b4854b2
3 changed files with 16 additions and 2 deletions

View File

@@ -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;