Skip to content
This repository was archived by the owner on Oct 22, 2025. It is now read-only.

Commit 1ec6e77

Browse files
committed
fix memory issue
1 parent 6752391 commit 1ec6e77

File tree

4 files changed

+16
-15
lines changed

4 files changed

+16
-15
lines changed

src/ipc/smooth_contact/collisions/smooth_collision.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,16 @@ SmoothCollisionTemplate<max_vert, PrimitiveA, PrimitiveB>::
4646
VectorMax3d d =
4747
PrimitiveDistance<PrimitiveA, PrimitiveB>::compute_closest_direction(
4848
mesh, V, primitive0_, primitive1_, dtype);
49-
pA = std::make_shared<PrimitiveA>(
49+
pA = std::make_unique<PrimitiveA>(
5050
primitive0_, mesh, V, d, param);
51-
pB = std::make_shared<PrimitiveB>(
51+
pB = std::make_unique<PrimitiveB>(
5252
primitive1_, mesh, V, -d, param);
53+
54+
if (pA->n_vertices() + pB->n_vertices() > max_vert)
55+
logger().error(
56+
"Too many neighbors for collision pair! {} > {}! Increase max_vert_3d in common.hpp",
57+
pA->n_vertices() + pB->n_vertices(), max_vert);
58+
5359
int i = 0;
5460
for (auto& v : pA->vertex_ids())
5561
Super::vertices[i++] = v;
@@ -64,12 +70,6 @@ SmoothCollisionTemplate<max_vert, PrimitiveA, PrimitiveB>::
6470
primitive1_, PrimitiveDistType<PrimitiveA, PrimitiveB>::name, Super::is_active_);
6571
}
6672

67-
template <int max_vert, typename PrimitiveA, typename PrimitiveB>
68-
SmoothCollisionTemplate<max_vert, PrimitiveA, PrimitiveB>::
69-
~SmoothCollisionTemplate()
70-
{
71-
}
72-
7373
template <int max_vert, typename PrimitiveA, typename PrimitiveB>
7474
double SmoothCollisionTemplate<max_vert, PrimitiveA, PrimitiveB>::operator()(
7575
const Vector<

src/ipc/smooth_contact/collisions/smooth_collision.hpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ template <int max_vert> class SmoothCollision : public Collision<max_vert> {
3030

3131
public:
3232
constexpr static int max_size = Collision<max_vert>::max_size;
33-
virtual ~SmoothCollision() { }
33+
virtual ~SmoothCollision() = default;
3434

3535
bool is_active() const { return is_active_; }
3636

@@ -138,7 +138,7 @@ class SmoothCollisionTemplate : public SmoothCollision<max_vert> {
138138
const ParameterType& param,
139139
const double& dhat,
140140
const Eigen::MatrixXd& V);
141-
virtual ~SmoothCollisionTemplate();
141+
virtual ~SmoothCollisionTemplate() = default;
142142

143143
inline int n_dofs() const override { return pA->n_dofs() + pB->n_dofs(); }
144144
CollisionType type() const override;
@@ -183,9 +183,9 @@ class SmoothCollisionTemplate : public SmoothCollision<max_vert> {
183183
MatrixMax<double, max_size, max_size> compute_distance_hessian(
184184
const Vector<double, -1, max_size>& positions) const override;
185185

186-
protected:
187-
std::shared_ptr<PrimitiveA> pA;
188-
std::shared_ptr<PrimitiveB> pB;
186+
private:
187+
std::unique_ptr<PrimitiveA> pA;
188+
std::unique_ptr<PrimitiveB> pB;
189189
};
190190

191191
} // namespace ipc

src/ipc/smooth_contact/common.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ constexpr static int n_vert_neighbors_2d = 3;
88
constexpr static int n_edge_neighbors_2d = 2;
99
constexpr static int max_vert_2d =
1010
2 * std::max(n_vert_neighbors_2d, n_edge_neighbors_2d);
11-
constexpr static int n_vert_neighbors_3d = 15; // increase me if needed
11+
constexpr static int n_vert_neighbors_3d = 20; // increase me if needed
1212
constexpr static int n_edge_neighbors_3d = 4;
1313
constexpr static int n_face_neighbors_3d = 3;
14-
constexpr static int max_vert_3d = 24;
14+
constexpr static int max_vert_3d = n_vert_neighbors_3d * 2;
1515

1616
template <int dim> class MaxVertices;
1717
template <> class MaxVertices<2> { public: static constexpr int value = max_vert_2d; };

src/ipc/smooth_contact/primitives/point3.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ class Point3 : public Primitive {
2121
const long& id,
2222
const CollisionMesh& mesh,
2323
const Eigen::MatrixXd& vertices);
24+
virtual ~Point3() = default;
2425

2526
int n_vertices() const override;
2627
int n_dofs() const override { return n_vertices() * dim; }

0 commit comments

Comments
 (0)