Skip to content
This repository was archived by the owner on Jan 21, 2022. It is now read-only.

Commit 8acfa3b

Browse files
committed
changed glPointCloud to a unique pointer to avoid memory leakage, because GLObject does not define a copy operator.
1 parent a5f4086 commit 8acfa3b

3 files changed

Lines changed: 14 additions & 15 deletions

File tree

include/pointcloud.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#include "glpointcloud.h"
44
#include <QVector3D>
55
#include <QOpenGLFunctions_4_3_Core>
6+
#include <memory>
67

78
class PointCloud
89
{
@@ -13,7 +14,7 @@ class PointCloud
1314

1415
int pointcloudId_;
1516
bool isVisible_;
16-
GLPointCloud glPointCloud_;
17+
std::unique_ptr<GLPointCloud> glPointCloud_;
1718
QImage colorscheme; // Color scheme of the point cloud. The line from texture coordinates (0,0) to (1,1) defines color(intensity)
1819

1920
private:

src/glwidget.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -192,8 +192,8 @@ GLWidget::paintGL()
192192
RenderObject(object);
193193
}
194194

195-
if (pointcloud_.isVisible_) {
196-
RenderObject(&pointcloud_.glPointCloud_);
195+
if (pointcloud_.isVisible_ && pointcloud_.glPointCloud_ != nullptr) {
196+
RenderObject(pointcloud_.glPointCloud_.get());
197197
}
198198

199199
foreach (GLObject* object, simulationObjects_)

src/pointcloud.cpp

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,8 @@ PointCloud::PointCloud(int id, QOpenGLFunctions_4_3_Core* functions, const QStri
44
: pointcloudId_(id),
55
isVisible_(true),
66
functions_(functions),
7-
srcPath_(srcPath),
8-
glPointCloud_(functions, srcPath)
7+
srcPath_(srcPath)
98
{
10-
glPointCloud_.id_ = "point_cloud_"+QString::number(id);
119
if (!colorscheme.load(srcPath + "Resources/Images/PointCloudColors.png")) {
1210
qDebug() << "Failed to open point cloud color scheme (" << srcPath << "Resources/Images/PointCloudColors.png)";
1311
}
@@ -17,17 +15,17 @@ PointCloud::PointCloud(int id, QOpenGLFunctions_4_3_Core* functions, const QStri
1715
void
1816
PointCloud::UpdatePointCloud(const QVector<PointStruct>& pm)
1917
{
20-
glPointCloud_ = GLPointCloud(functions_, srcPath_);
21-
glPointCloud_.id_ = "point_cloud_" + QString::number(pointcloudId_);
18+
glPointCloud_ = std::make_unique<GLPointCloud>(functions_, srcPath_);
19+
glPointCloud_->id_ = "point_cloud_" + QString::number(pointcloudId_);
2220
// Copy data from pm to glPointCloud_
2321
for (const PointStruct& p : pm) {
24-
glPointCloud_.vertices_.append(p.position);
25-
glPointCloud_.texCoords_.append(QVector2D(p.color, p.color));
22+
glPointCloud_->vertices_.append(p.position);
23+
glPointCloud_->texCoords_.append(QVector2D(p.color, p.color));
2624
}
2725
// set up the globject
28-
glPointCloud_.Init();
29-
glPointCloud_.SetColor(Qt::white);
30-
glPointCloud_.SetTexture(colorscheme, false, GL_CLAMP_TO_EDGE);
31-
glPointCloud_.SetObjectType(ObjectType::None);
32-
glPointCloud_.UpdateVertexBuffer();
26+
glPointCloud_->Init();
27+
glPointCloud_->SetColor(Qt::white);
28+
glPointCloud_->SetTexture(colorscheme, false, GL_CLAMP_TO_EDGE);
29+
glPointCloud_->SetObjectType(ObjectType::None);
30+
glPointCloud_->UpdateVertexBuffer();
3331
}

0 commit comments

Comments
 (0)