Revert "Fix race conditions caused by Array <-> GLBufferObject interactions (Bug #3580)"

This reverts commit 115e563a7a.
coverity_scan^2
scrawl 8 years ago
parent f2174ee9f4
commit 6a37909ee7

@ -40,45 +40,32 @@ void ShapeData::read(NIFStream *nif)
{ {
int verts = nif->getUShort(); int verts = nif->getUShort();
// Assign a VBO right off the bat to avoid race conditions later, in case two threads load this data into a Geometry at the same time vertices = new osg::Vec3Array;
osg::ref_ptr<osg::VertexBufferObject> vbo = new osg::VertexBufferObject; if(nif->getInt())
if(nif->getInt() && verts)
{
vertices = new osg::Vec3Array;
nif->getVector3s(vertices, verts); nif->getVector3s(vertices, verts);
vertices->setVertexBufferObject(vbo);
}
if(nif->getInt() && verts) normals = new osg::Vec3Array(osg::Array::BIND_PER_VERTEX);
{ if(nif->getInt())
normals = new osg::Vec3Array(osg::Array::BIND_PER_VERTEX);
nif->getVector3s(normals, verts); nif->getVector3s(normals, verts);
normals->setVertexBufferObject(vbo);
}
center = nif->getVector3(); center = nif->getVector3();
radius = nif->getFloat(); radius = nif->getFloat();
if(nif->getInt() && verts) colors = new osg::Vec4Array(osg::Array::BIND_PER_VERTEX);
{ if(nif->getInt())
colors = new osg::Vec4Array(osg::Array::BIND_PER_VERTEX);
nif->getVector4s(colors, verts); nif->getVector4s(colors, verts);
colors->setVertexBufferObject(vbo);
}
// Only the first 6 bits are used as a count. I think the rest are // Only the first 6 bits are used as a count. I think the rest are
// flags of some sort. // flags of some sort.
int uvs = nif->getUShort(); int uvs = nif->getUShort();
uvs &= 0x3f; uvs &= 0x3f;
if(nif->getInt() && verts) if(nif->getInt())
{ {
uvlist.resize(uvs); uvlist.resize(uvs);
for(int i = 0;i < uvs;i++) for(int i = 0;i < uvs;i++)
{ {
osg::Vec2Array* list = uvlist[i] = new osg::Vec2Array(osg::Array::BIND_PER_VERTEX); osg::Vec2Array* list = uvlist[i] = new osg::Vec2Array(osg::Array::BIND_PER_VERTEX);
list->setVertexBufferObject(vbo);
nif->getVector2s(list, verts); nif->getVector2s(list, verts);
// flip the texture coordinates to convert them to the OpenGL convention of bottom-left image origin // flip the texture coordinates to convert them to the OpenGL convention of bottom-left image origin
@ -99,14 +86,8 @@ void NiTriShapeData::read(NIFStream *nif)
// We have three times as many vertices as triangles, so this // We have three times as many vertices as triangles, so this
// is always equal to tris*3. // is always equal to tris*3.
int cnt = nif->getInt(); int cnt = nif->getInt();
if (cnt) triangles = new osg::DrawElementsUShort(osg::PrimitiveSet::TRIANGLES);
{ nif->getUShorts(triangles, cnt);
triangles = new osg::DrawElementsUShort(osg::PrimitiveSet::TRIANGLES);
nif->getUShorts(triangles, cnt);
// Assign an EBO right off the bat to avoid race conditions later, in case two threads load this data into a Geometry at the same time
triangles->setElementBufferObject(new osg::ElementBufferObject);
}
// Read the match list, which lists the vertices that are equal to // Read the match list, which lists the vertices that are equal to
// vertices. We don't actually need need this for anything, so // vertices. We don't actually need need this for anything, so

@ -268,9 +268,7 @@ void BulletNifLoader::handleNiTriShape(const Nif::NiTriShape *shape, int flags,
if (shape->data.empty()) if (shape->data.empty())
return; return;
if (shape->data->triangles->empty())
const Nif::NiTriShapeData *data = shape->data.getPtr();
if (!data->triangles || !data->vertices)
return; return;
if (isAnimated) if (isAnimated)
@ -280,6 +278,8 @@ void BulletNifLoader::handleNiTriShape(const Nif::NiTriShape *shape, int flags,
btTriangleMesh* childMesh = new btTriangleMesh(); btTriangleMesh* childMesh = new btTriangleMesh();
const Nif::NiTriShapeData *data = shape->data.getPtr();
childMesh->preallocateVertices(data->vertices->size()); childMesh->preallocateVertices(data->vertices->size());
childMesh->preallocateIndices(data->triangles->size()); childMesh->preallocateIndices(data->triangles->size());
@ -320,6 +320,7 @@ void BulletNifLoader::handleNiTriShape(const Nif::NiTriShape *shape, int flags,
mStaticMesh = new btTriangleMesh(false); mStaticMesh = new btTriangleMesh(false);
// Static shape, just transform all vertices into position // Static shape, just transform all vertices into position
const Nif::NiTriShapeData *data = shape->data.getPtr();
const osg::Vec3Array& vertices = *data->vertices; const osg::Vec3Array& vertices = *data->vertices;
const osg::DrawElementsUShort& triangles = *data->triangles; const osg::DrawElementsUShort& triangles = *data->triangles;

@ -898,10 +898,6 @@ namespace NifOsg
osg::BoundingBox box; osg::BoundingBox box;
osg::Vec3Array* verts = particledata->vertices;
if (!verts)
return;
int i=0; int i=0;
for (std::vector<Nif::NiParticleSystemController::Particle>::const_iterator it = partctrl->particles.begin(); for (std::vector<Nif::NiParticleSystemController::Particle>::const_iterator it = partctrl->particles.begin();
i<particledata->activeCount && it != partctrl->particles.end(); ++it, ++i) i<particledata->activeCount && it != partctrl->particles.end(); ++it, ++i)
@ -916,11 +912,11 @@ namespace NifOsg
// Note this position and velocity is not correct for a particle system with absolute reference frame, // Note this position and velocity is not correct for a particle system with absolute reference frame,
// which can not be done in this loader since we are not attached to the scene yet. Will be fixed up post-load in the SceneManager. // which can not be done in this loader since we are not attached to the scene yet. Will be fixed up post-load in the SceneManager.
created->setVelocity(particle.velocity); created->setVelocity(particle.velocity);
const osg::Vec3f& position = verts->at(particle.vertex); const osg::Vec3f& position = particledata->vertices->at(particle.vertex);
created->setPosition(position); created->setPosition(position);
osg::Vec4f partcolor (1.f,1.f,1.f,1.f); osg::Vec4f partcolor (1.f,1.f,1.f,1.f);
if (particledata->colors.valid() && particle.vertex < int(particledata->colors->size())) if (particle.vertex < int(particledata->colors->size()))
partcolor = particledata->colors->at(particle.vertex); partcolor = particledata->colors->at(particle.vertex);
float size = particledata->sizes.at(particle.vertex) * partctrl->size; float size = particledata->sizes.at(particle.vertex) * partctrl->size;
@ -1082,7 +1078,7 @@ namespace NifOsg
geometry->setVertexArray(data->vertices); geometry->setVertexArray(data->vertices);
if (data->normals) if (!data->normals->empty())
geometry->setNormalArray(data->normals); geometry->setNormalArray(data->normals);
int textureStage = 0; int textureStage = 0;
@ -1100,10 +1096,10 @@ namespace NifOsg
geometry->setTexCoordArray(textureStage, data->uvlist[uvSet]); geometry->setTexCoordArray(textureStage, data->uvlist[uvSet]);
} }
if (data->colors) if (!data->colors->empty())
geometry->setColorArray(data->colors); geometry->setColorArray(data->colors);
if (data->triangles) if (!data->triangles->empty())
geometry->addPrimitiveSet(data->triangles); geometry->addPrimitiveSet(data->triangles);
// osg::Material properties are handled here for two reasons: // osg::Material properties are handled here for two reasons:
@ -1112,7 +1108,7 @@ namespace NifOsg
// above the actual renderable would be tedious. // above the actual renderable would be tedious.
std::vector<const Nif::Property*> drawableProps; std::vector<const Nif::Property*> drawableProps;
collectDrawableProperties(triShape, drawableProps); collectDrawableProperties(triShape, drawableProps);
applyDrawableProperties(parentNode, drawableProps, composite, data->colors.valid(), animflags, false); applyDrawableProperties(parentNode, drawableProps, composite, !data->colors->empty(), animflags, false);
} }
void handleTriShape(const Nif::NiTriShape* triShape, osg::Group* parentNode, SceneUtil::CompositeStateSetUpdater* composite, const std::vector<int>& boundTextures, int animflags) void handleTriShape(const Nif::NiTriShape* triShape, osg::Group* parentNode, SceneUtil::CompositeStateSetUpdater* composite, const std::vector<int>& boundTextures, int animflags)

Loading…
Cancel
Save