Skip to content

Commit

Permalink
Fix memory patch in vhacd
Browse files Browse the repository at this point in the history
  • Loading branch information
TothBenoit committed Dec 16, 2024
1 parent ef68668 commit a0ae5a8
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 22 deletions.
15 changes: 8 additions & 7 deletions hl.sln
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.12.35506.116 d17.12
VisualStudioVersion = 17.12.35506.116
MinimumVisualStudioVersion = 10.0.40219.1
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "sdl", "libs\sdl\sdl.vcxproj", "{12049F27-EA26-4A33-ADF8-E542C4167C00}"
ProjectSection(ProjectDependencies) = postProject
Expand All @@ -17,17 +17,18 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "fmt", "libs\fmt\fmt.vcxproj
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "hl", "hl.vcxproj", "{BBF750D2-6DD2-4A41-AC3A-07C070B94FA1}"
ProjectSection(ProjectDependencies) = postProject
{76E4DB00-8114-4B96-BA76-39D800F8D5EE} = {76E4DB00-8114-4B96-BA76-39D800F8D5EE}
{12049F27-EA26-4A33-ADF8-E542C4167C00} = {12049F27-EA26-4A33-ADF8-E542C4167C00}
{43AAD9DB-4708-46B6-AAE8-A5DB95A0B573} = {43AAD9DB-4708-46B6-AAE8-A5DB95A0B573}
{540E0E11-B7B1-43F8-B107-0867B2D97F74} = {540E0E11-B7B1-43F8-B107-0867B2D97F74}
{7DDA1414-6675-45C7-8254-42057901F865} = {7DDA1414-6675-45C7-8254-42057901F865}
{6534D221-34DF-404A-AFCD-6DEC9BBC9798} = {6534D221-34DF-404A-AFCD-6DEC9BBC9798}
{12049F27-EA26-4A33-ADF8-E542C4167C00} = {12049F27-EA26-4A33-ADF8-E542C4167C00}
{76E4DB00-8114-4B96-BA76-39D800F8D5EE} = {76E4DB00-8114-4B96-BA76-39D800F8D5EE}
{7DDA1414-6675-45C7-8254-42057901F865} = {7DDA1414-6675-45C7-8254-42057901F865}
{C6213FBF-BC2B-4235-A827-84A60E848C52} = {C6213FBF-BC2B-4235-A827-84A60E848C52}
{E3F735ED-9701-46BE-A86C-C61D3CE0D525} = {E3F735ED-9701-46BE-A86C-C61D3CE0D525}
{EC2DCE5C-267A-4050-8DDE-5BF58FF08E31} = {EC2DCE5C-267A-4050-8DDE-5BF58FF08E31}
{F9A2435E-D545-43EB-B471-A4497D96A71B} = {F9A2435E-D545-43EB-B471-A4497D96A71B}
{EC79BC9F-9947-4BCC-92F9-14F90CDE4B04} = {EC79BC9F-9947-4BCC-92F9-14F90CDE4B04}
{C6213FBF-BC2B-4235-A827-84A60E848C52} = {C6213FBF-BC2B-4235-A827-84A60E848C52}
{F4D939D6-88D6-4FF2-874A-7BECF75A01C2} = {F4D939D6-88D6-4FF2-874A-7BECF75A01C2}
{43AAD9DB-4708-46B6-AAE8-A5DB95A0B573} = {43AAD9DB-4708-46B6-AAE8-A5DB95A0B573}
{F9A2435E-D545-43EB-B471-A4497D96A71B} = {F9A2435E-D545-43EB-B471-A4497D96A71B}
EndProjectSection
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ui", "libs\ui\ui.vcxproj", "{6534D221-34DF-404A-AFCD-6DEC9BBC9798}"
Expand Down
29 changes: 14 additions & 15 deletions libs/heaps/vhacd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@
#include <VHACD.h>
#include <hl.h>

typedef VHACD::IVHACD vhacd;
typedef struct {
VHACD::IVHACD* pInstance;
std::vector<VHACD::IVHACD::ConvexHull> convexHulls;
} vhacd;

struct convex_hull {
vbyte* points;
Expand All @@ -25,21 +28,22 @@ struct convex_hull {
};

HL_PRIM vhacd* HL_NAME(create_vhacd)() {
return VHACD::CreateVHACD();
return new vhacd{ VHACD::CreateVHACD() };
}

HL_PRIM bool HL_NAME(vhacd_compute)(vhacd* pVhacd, float* pPoints, uint32_t countPoints, uint32_t* pTriangles, uint32_t countTriangle, VHACD::IVHACD::Parameters* pParameters ) {
return pVhacd->Compute(pPoints, countPoints, pTriangles, countTriangle, *pParameters);
return pVhacd->pInstance->Compute(pPoints, countPoints, pTriangles, countTriangle, *pParameters);
}

HL_PRIM int HL_NAME(vhacd_get_n_convex_hulls)(vhacd* pVhacd) {
return pVhacd->GetNConvexHulls();
return pVhacd->pInstance->GetNConvexHulls();
}

HL_PRIM bool HL_NAME(vhacd_get_convex_hull)(vhacd* pVhacd, int index, convex_hull* pConvexHull ) {
VHACD::IVHACD::ConvexHull convexHull;
if ( !pVhacd->GetConvexHull(index, convexHull) )
return false;
pVhacd->convexHulls.emplace_back();
VHACD::IVHACD::ConvexHull& convexHull = pVhacd->convexHulls.back();
if ( !pVhacd->pInstance->GetConvexHull(index, convexHull) )
return false;

pConvexHull->points = (vbyte*)convexHull.m_points.data();
pConvexHull->pointCount = (int)convexHull.m_points.size();
Expand All @@ -57,21 +61,16 @@ HL_PRIM bool HL_NAME(vhacd_get_convex_hull)(vhacd* pVhacd, int index, convex_hul
pConvexHull->boundsMaxY = convexHull.mBmax[1];
pConvexHull->boundsMaxZ = convexHull.mBmax[2];

// To avoid freeing convex hull memory
std::vector<VHACD::Vertex> fakePoints{};
convexHull.m_points = fakePoints;
std::vector<VHACD::Triangle> fakeTriangles{};
convexHull.m_triangles = fakeTriangles;

return true;
}

HL_PRIM void HL_NAME(vhacd_clean)(vhacd* pVhacd) {
pVhacd->Clean();
pVhacd->pInstance->Clean();
}

HL_PRIM void HL_NAME(vhacd_release)(vhacd* pVhacd) {
pVhacd->Release();
pVhacd->pInstance->Release();
delete pVhacd;
}

#define _VHACD _ABSTRACT(vhacd)
Expand Down

0 comments on commit a0ae5a8

Please sign in to comment.