Skip to content

Commit

Permalink
fix #7 : segmentation fault
Browse files Browse the repository at this point in the history
Also fixed Linux and Windows build error with string issues

Peace~
  • Loading branch information
but0n committed Mar 10, 2018
1 parent 8bd49f3 commit c6dd0b4
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions main/build.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
#include "build.h"
#include "../recast/InputGeom.h"
#include "../recast/MeshLoaderObj.h"
#include <string.h>

// #define DEBUG
#define OUTPUT_STRING

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

static char obj[262144];

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


char obj[262144];
char *p_obj = obj;

do {
Expand Down Expand Up @@ -455,6 +455,7 @@ char *build(
}
}
} while (0);
*p_obj = '\0';

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

char obj[262144];
char *p_obj = obj;
char buf[262144];
char *p_obj = buf;

const float cs = m_pmesh->cs;
const float ch = m_pmesh->ch;
Expand Down Expand Up @@ -513,7 +514,7 @@ int exportAsObj(const char *path) {
p_obj += sprintf(p_obj, "\n");
}

fputs(obj, fp);
fputs(buf, fp);
fclose(fp);
fp = NULL;

Expand Down

0 comments on commit c6dd0b4

Please sign in to comment.