Fixed crash in fbx import pipeline

This commit is contained in:
2013-11-23 17:02:17 -08:00
parent 9cd9a8474c
commit 61fde7700b
6 changed files with 40 additions and 32 deletions

View File

@@ -110,6 +110,8 @@ KRMesh::~KRMesh() {
} }
void KRMesh::releaseData() { void KRMesh::releaseData() {
m_hasTransparency = false;
m_submeshes.clear();
if(m_pIndexBaseData) { if(m_pIndexBaseData) {
m_pIndexBaseData->unlock(); m_pIndexBaseData->unlock();
delete m_pIndexBaseData; delete m_pIndexBaseData;
@@ -397,7 +399,7 @@ void KRMesh::renderSubmesh(int iSubmesh, KRNode::RenderPass renderPass, const st
void KRMesh::LoadData(const KRMesh::mesh_info &mi, bool calculate_normals, bool calculate_tangents) { void KRMesh::LoadData(const KRMesh::mesh_info &mi, bool calculate_normals, bool calculate_tangents) {
clearBuffers(); releaseData();
// TODO, FINDME - These values should be passed as a parameter and set by GUI flags // TODO, FINDME - These values should be passed as a parameter and set by GUI flags
bool use_short_vertexes = false; bool use_short_vertexes = false;
@@ -645,10 +647,6 @@ KRVector3 KRMesh::getMaxPoint() const {
return m_maxPoint; return m_maxPoint;
} }
void KRMesh::clearBuffers() {
m_submeshes.clear();
}
int KRMesh::getLODCoverage() const { int KRMesh::getLODCoverage() const {
return m_lodCoverage; return m_lodCoverage;
} }

View File

@@ -250,9 +250,6 @@ private:
int m_vertex_size; int m_vertex_size;
void updateAttributeOffsets(); void updateAttributeOffsets();
void clearBuffers();
void setName(const std::string name); void setName(const std::string name);

View File

@@ -45,11 +45,14 @@ public:
KRMeshStreamer(KRContext &context); KRMeshStreamer(KRContext &context);
~KRMeshStreamer(); ~KRMeshStreamer();
void startStreamer();
private: private:
KRContext &m_context; KRContext &m_context;
std::thread m_thread; std::thread m_thread;
std::atomic<bool> m_stop; std::atomic<bool> m_stop;
std::atomic<bool> m_running;
void run(); void run();
}; };

View File

@@ -28,29 +28,40 @@ NSOpenGLContext *gMeshStreamerContext = nil;
KRMeshStreamer::KRMeshStreamer(KRContext &context) : m_context(context) KRMeshStreamer::KRMeshStreamer(KRContext &context) : m_context(context)
{ {
m_running = false;
#if TARGET_OS_IPHONE
gMeshStreamerContext = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES2 sharegroup: [EAGLContext currentContext].sharegroup];
#elif TARGET_OS_MAC
NSOpenGLPixelFormatAttribute pixelFormatAttributes[] =
{
NSOpenGLPFAOpenGLProfile, NSOpenGLProfileVersion3_2Core,
0
};
NSOpenGLPixelFormat *pixelFormat = [[[NSOpenGLPixelFormat alloc] initWithAttributes:pixelFormatAttributes] autorelease];
gMeshStreamerContext = [[[NSOpenGLContext alloc] initWithFormat: pixelFormat shareContext: [NSOpenGLContext currentContext] ] autorelease];
#else
#error Unsupported Platform
#endif
m_stop = false; m_stop = false;
m_thread = std::thread(&KRMeshStreamer::run, this); }
void KRMeshStreamer::startStreamer()
{
if(!m_running) {
m_running = true;
#if TARGET_OS_IPHONE
gMeshStreamerContext = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES2 sharegroup: [EAGLContext currentContext].sharegroup];
#elif TARGET_OS_MAC
NSOpenGLPixelFormatAttribute pixelFormatAttributes[] =
{
NSOpenGLPFAOpenGLProfile, NSOpenGLProfileVersion3_2Core,
0
};
NSOpenGLPixelFormat *pixelFormat = [[[NSOpenGLPixelFormat alloc] initWithAttributes:pixelFormatAttributes] autorelease];
gMeshStreamerContext = [[[NSOpenGLContext alloc] initWithFormat: pixelFormat shareContext: [NSOpenGLContext currentContext] ] autorelease];
#else
#error Unsupported Platform
#endif
m_thread = std::thread(&KRMeshStreamer::run, this);
}
} }
KRMeshStreamer::~KRMeshStreamer() KRMeshStreamer::~KRMeshStreamer()
{ {
m_stop = true; if(m_running) {
m_thread.join(); m_stop = true;
m_thread.join();
m_running = false;
}
[gMeshStreamerContext release]; [gMeshStreamerContext release];
} }

View File

@@ -55,7 +55,6 @@ private:
std::atomic<bool> m_running; std::atomic<bool> m_running;
void run(); void run();
}; };
#endif /* defined(KRTEXTURESTREAMER_H) */ #endif /* defined(KRTEXTURESTREAMER_H) */

View File

@@ -27,7 +27,6 @@ NSOpenGLContext *gTextureStreamerContext = nil;
#error Unsupported Platform #error Unsupported Platform
#endif #endif
KRTextureStreamer::KRTextureStreamer(KRContext &context) : m_context(context) KRTextureStreamer::KRTextureStreamer(KRContext &context) : m_context(context)
{ {
m_running = false; m_running = false;
@@ -65,8 +64,11 @@ void KRTextureStreamer::startStreamer()
KRTextureStreamer::~KRTextureStreamer() KRTextureStreamer::~KRTextureStreamer()
{ {
m_stop = true; if(m_running) {
m_thread.join(); m_stop = true;
m_thread.join();
m_running = false;
}
[gTextureStreamerContext release]; [gTextureStreamerContext release];
} }
@@ -92,6 +94,4 @@ void KRTextureStreamer::run()
} }
std::this_thread::sleep_for( sleep_duration ); std::this_thread::sleep_for( sleep_duration );
} }
m_running = false;
} }