Merge pull request #9088 from sethalves/fix-polyvox-memory-leak

fix polyvox memory leak
This commit is contained in:
Brad Hefta-Gaub 2016-11-17 12:23:13 -08:00 committed by GitHub
commit 91f90400a9
4 changed files with 42 additions and 16 deletions

View file

@ -1139,8 +1139,8 @@ void RenderablePolyVoxEntityItem::getMesh() {
auto indexBuffer = std::make_shared<gpu::Buffer>(vecIndices.size() * sizeof(uint32_t),
(gpu::Byte*)vecIndices.data());
auto indexBufferPtr = gpu::BufferPointer(indexBuffer);
auto indexBufferView = new gpu::BufferView(indexBufferPtr, gpu::Element(gpu::SCALAR, gpu::UINT32, gpu::RAW));
mesh->setIndexBuffer(*indexBufferView);
gpu::BufferView indexBufferView(indexBufferPtr, gpu::Element(gpu::SCALAR, gpu::UINT32, gpu::RAW));
mesh->setIndexBuffer(indexBufferView);
const std::vector<PolyVox::PositionMaterialNormal>& vecVertices = polyVoxMesh.getVertices();
auto vertexBuffer = std::make_shared<gpu::Buffer>(vecVertices.size() * sizeof(PolyVox::PositionMaterialNormal),
@ -1150,10 +1150,10 @@ void RenderablePolyVoxEntityItem::getMesh() {
if (vertexBufferPtr->getSize() > sizeof(float) * 3) {
vertexBufferSize = vertexBufferPtr->getSize() - sizeof(float) * 3;
}
auto vertexBufferView = new gpu::BufferView(vertexBufferPtr, 0, vertexBufferSize,
sizeof(PolyVox::PositionMaterialNormal),
gpu::Element(gpu::VEC3, gpu::FLOAT, gpu::RAW));
mesh->setVertexBuffer(*vertexBufferView);
gpu::BufferView vertexBufferView(vertexBufferPtr, 0, vertexBufferSize,
sizeof(PolyVox::PositionMaterialNormal),
gpu::Element(gpu::VEC3, gpu::FLOAT, gpu::RAW));
mesh->setVertexBuffer(vertexBufferView);
mesh->addAttribute(gpu::Stream::NORMAL,
gpu::BufferView(vertexBufferPtr,
sizeof(float) * 3,
@ -1323,14 +1323,14 @@ void RenderablePolyVoxEntityItem::setCollisionPoints(ShapeInfo::PointCollection
// include the registrationPoint in the shape key, because the offset is already
// included in the points and the shapeManager wont know that the shape has changed.
withWriteLock([&] {
QString shapeKey = QString(_voxelData.toBase64()) + "," +
QString::number(_registrationPoint.x) + "," +
QString::number(_registrationPoint.y) + "," +
QString::number(_registrationPoint.z);
_shapeInfo.setParams(SHAPE_TYPE_COMPOUND, collisionModelDimensions, shapeKey);
_shapeInfo.setPointCollection(pointCollection);
_meshDirty = false;
});
QString shapeKey = QString(_voxelData.toBase64()) + "," +
QString::number(_registrationPoint.x) + "," +
QString::number(_registrationPoint.y) + "," +
QString::number(_registrationPoint.z);
_shapeInfo.setParams(SHAPE_TYPE_COMPOUND, collisionModelDimensions, shapeKey);
_shapeInfo.setPointCollection(pointCollection);
_meshDirty = false;
});
}
void RenderablePolyVoxEntityItem::setXNNeighborID(const EntityItemID& xNNeighborID) {
@ -1439,3 +1439,16 @@ void RenderablePolyVoxEntityItem::bonkNeighbors() {
currentZNNeighbor->setVolDataDirty();
}
}
void RenderablePolyVoxEntityItem::locationChanged(bool tellPhysics) {
EntityItem::locationChanged(tellPhysics);
if (!_pipeline || !render::Item::isValidID(_myItem)) {
return;
}
render::ScenePointer scene = AbstractViewStateInterface::instance()->getMain3DScene();
render::PendingChanges pendingChanges;
pendingChanges.updateItem<PolyVoxPayload>(_myItem, [](PolyVoxPayload& payload) {});
scene->enqueuePendingChanges(pendingChanges);
}

View file

@ -141,6 +141,9 @@ public:
// Transparent polyvox didn't seem to be working so disable for now
bool isTransparent() override { return false; }
protected:
virtual void locationChanged(bool tellPhysics = true) override;
private:
// The PolyVoxEntityItem class has _voxelData which contains dimensions and compressed voxel data. The dimensions
// may not match _voxelVolumeSize.

View file

@ -25,6 +25,14 @@ void Buffer::updateBufferCPUMemoryUsage(Size prevObjectSize, Size newObjectSize)
}
}
void Buffer::incrementBufferCPUCount() {
_bufferCPUCount++;
}
void Buffer::decrementBufferCPUCount() {
_bufferCPUCount--;
}
uint32_t Buffer::getBufferCPUCount() {
return _bufferCPUCount.load();
}
@ -43,7 +51,7 @@ Buffer::Size Buffer::getBufferGPUMemoryUsage() {
Buffer::Buffer(Size pageSize) :
_renderPages(pageSize), _pages(pageSize) {
_bufferCPUCount++;
Buffer::incrementBufferCPUCount();
}
Buffer::Buffer(Size size, const Byte* bytes, Size pageSize) : Buffer(pageSize) {
@ -61,7 +69,7 @@ Buffer& Buffer::operator=(const Buffer& buf) {
}
Buffer::~Buffer() {
_bufferCPUCount--;
Buffer::decrementBufferCPUCount();
Buffer::updateBufferCPUMemoryUsage(_sysmem.getSize(), 0);
}

View file

@ -27,6 +27,8 @@ class Buffer : public Resource {
static std::atomic<uint32_t> _bufferCPUCount;
static std::atomic<Size> _bufferCPUMemoryUsage;
static void updateBufferCPUMemoryUsage(Size prevObjectSize, Size newObjectSize);
static void incrementBufferCPUCount();
static void decrementBufferCPUCount();
public:
using Flag = PageManager::Flag;