Skip to content

Commit c6dd0b4

Browse files
committed
fix #7 : segmentation fault
Also fixed Linux and Windows build error with string issues Peace~
1 parent 8bd49f3 commit c6dd0b4

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

main/build.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
#include "build.h"
55
#include "../recast/InputGeom.h"
66
#include "../recast/MeshLoaderObj.h"
7+
#include <string.h>
78

89
// #define DEBUG
9-
#define OUTPUT_STRING
1010

1111
rcConfig m_cfg;
1212
class rcContext *m_ctx = new rcContext;
@@ -27,6 +27,7 @@ rcContourSet *m_cset;
2727
rcPolyMesh *m_pmesh; // Navigation mesh 数据
2828
rcPolyMeshDetail *m_dmesh; // Navigation mesh detail 数据
2929

30+
static char obj[262144];
3031

3132
int load(const char *str) {
3233
if (!m_geom->load(m_ctx, str)) {
@@ -420,7 +421,6 @@ char *build(
420421
// See duDebugDrawPolyMesh or dtCreateNavMeshData as examples how to access the data.
421422

422423

423-
char obj[262144];
424424
char *p_obj = obj;
425425

426426
do {
@@ -455,6 +455,7 @@ char *build(
455455
}
456456
}
457457
} while (0);
458+
*p_obj = '\0';
458459

459460
#ifdef DEBUG
460461
float m_totalBuildTimeMs = m_ctx->getAccumulatedTime(RC_TIMER_TOTAL) / 1000.0f;
@@ -478,8 +479,8 @@ int exportAsObj(const char *path) {
478479
return 1;
479480
}
480481

481-
char obj[262144];
482-
char *p_obj = obj;
482+
char buf[262144];
483+
char *p_obj = buf;
483484

484485
const float cs = m_pmesh->cs;
485486
const float ch = m_pmesh->ch;
@@ -513,7 +514,7 @@ int exportAsObj(const char *path) {
513514
p_obj += sprintf(p_obj, "\n");
514515
}
515516

516-
fputs(obj, fp);
517+
fputs(buf, fp);
517518
fclose(fp);
518519
fp = NULL;
519520

0 commit comments

Comments
 (0)