I've faced with some problem. Here an example:
/*begin example*/
void MyClass::generateTerrain(blah-blah-blah) {
/*generating code here*/
};
typedef void(*proc)(void*data);
static void MyClass::gen(void * data) {
((MyClass*)data)->generateTerrain(blah-blah-blah);
}
proc threadCallback = gen;
/*end example*/
Then I create thread in MyClass constructor:
/*begin code*/
...
GThreadRef thread = GThread::create("generate", threadCallback, this);
thread->start(G3D::USE_NEW_THREAD);
while(thread->running()) //Show loading progress screen while terrain
is generating
showProgressScreen();
//another initializations further
/*end code*/
In such way my application crashes. But if I start thread with
"thread->start(G3D::USE_CURRENT_THREAD)" then it's ok and well
started. What's problem?
Thanks! :)
It's okay :) I was busy too.
Program crashes with such message in log.txt:
<begin log>
Critical Error - phys.exe
Deleting thread while running.
Expression: m_status != STATUS_RUNNING
..\G3D.lib\source\GThread.cpp:54
<end log>
Here is the exact code I use:
//file Scene.h
...
/*this function will be used to create thread.
It's wrapper to generateTerrain()*/
static void threadCallback(void *data);
ArticulatedModel::Ref generateTerrain(...);
...
//file Scene.cpp
...
ArticulatedModel::Ref Scene::generateTerrain(...) {
...
return model;
}
void Scene::threadCallback(void *data) {
((Scene*)data)->ground = ((Scene*)data)->generateTerrain(...);
}
Scene::Scene() {
...
GThread::Ref thread = GThread::create("generate", threadCallback, this);
thread->start();
//Display LoadingProgress while terrain is generating
while(thread->running()) {
//Render animating picture here
...
}
In simple words I'd like to generate terrain and display loading
screen in separate threads so they would work simultaneously :)
[Content]
The resulting problem has led to the cessation of the program. Windows
will close the program, and if there is a known workaround, will
notify you.
And there are two buttons below: [Debug] [Close Program]
--
Vitaly
I localized the problem. It was how I generate landscape. If
MeshAlg::generateGrid is present in thread callback then application
crashes when thread finished. When it's commented out then it passes
well (but without landscape model of course). Now I need to come up
with workaround.
Many thanks to your suggestions! They were useful.
--
Vitaly
--
Vitaly
> msvcr100.dll!memcpy(unsigned char * dst, unsigned char * src, unsigned long count) Line 313 Asm
phys.exe!G3D::System::memcpy() + 0x32 bytes C++
phys.exe!G3D::VertexRange::updateInterleaved<G3D::Vector3,G3D::Vector3,G3D::Vector4,G3D::Vector2,G3D::Vector3>()
+ 0x11f bytes C++
phys.exe!G3D::VertexRange::createInterleaved<G3D::Vector3,G3D::Vector3,G3D::Vector4,G3D::Vector2,G3D::Vector3>()
+ 0x1c5 bytes C++
phys.exe!G3D::VertexRange::createInterleaved<G3D::Vector3,G3D::Vector3,G3D::Vector4,G3D::Vector2>()
+ 0x90 bytes C++
phys.exe!G3D::SuperSurface::CPUGeom::copyVertexDataToGPU() + 0x16c bytes C++
phys.exe!G3D::ArticulatedModel::Part::updateVAR() + 0x5c bytes C++
phys.exe!G3D::ArticulatedModel::updateAll() + 0x2cf bytes C++
phys.exe!Scene::generateTerrain(const
std::basic_string<char,std::char_traits<char>,std::allocator<char> > &
filename, float xExtent, float yExtent, G3D::Material::Specification
material, float zExtent, const G3D::Vector2 & texScale, bool
spaceCentered, bool twoSided) Line 360 C++
phys.exe!Scene::Scene(void (const
std::basic_string<char,std::char_traits<char>,std::allocator<char> >
&, void *)* c, void * data) Line 54 + 0xad bytes C++
phys.exe!Loki::sceneThreadProc(void * param) Line 270 + 0x27 bytes C++
phys.exe!G3D::_internal::BasicThread::threadMain() + 0x9 bytes C++
phys.exe!G3D::GThread::internalThreadProc() + 0x17 bytes C++
kernel32.dll!@BaseThreadInitThunk@12() + 0x12 bytes
ntdll.dll!___RtlUserThreadStart@8() + 0x27 bytes
ntdll.dll!__RtlUserThreadStart@8() + 0x1b bytes
memcpy.asm:313
mov [edi+ecx*4-12],eax ;U - put dword into destination
--
Vitaly
I've found the issue. Sorry for misleading you. I'm confused with pointers
--
Vitaly
Not a problem. Been too busy myself to really help. I wont be around to answer emails for a couple weeks.
Happy Holidays!
corey