G3D::GThread

35 views
Skip to first unread message

Vitaly Shevtsov

unread,
Dec 7, 2011, 2:57:30 PM12/7/11
to Рассылка G3D
Good evening!

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! :)

Corey Taylor

unread,
Dec 12, 2011, 10:37:45 PM12/12/11
to g3d-...@googlegroups.com
I've been unavailable, so sorry for the delay.
 
Where does your application crash?  There's no way to debug just from what you have shown.
 
corey

Vitaly Shevtsov

unread,
Dec 13, 2011, 9:55:30 AM12/13/11
to g3d-...@googlegroups.com
Hello, Corey!

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 :)

Corey Taylor

unread,
Dec 13, 2011, 11:16:35 PM12/13/11
to g3d-...@googlegroups.com
Vitaly,
 
I believe the issue is how running() works. it only returns true if the thread's procedure is actually running, not just if you've asked the operating system to spawn the thread.
 
If you use while (! thread->completed())  does it work?
 
corey

Vitaly Shevtsov

unread,
Dec 14, 2011, 6:36:13 AM12/14/11
to g3d-...@googlegroups.com
The same issue, Corey. I've noticed strange thing: when I use any code
inside the brackets "{ }" in "while keyword" debugAssertM says:
"Expression: m_status != STATUS_RUNNING". But when I dont't use any
code here it just crashes with system windows error. I cannot give it
verbatim 'cause it's in russian but it sounds like this:

[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

Corey Taylor

unread,
Dec 14, 2011, 11:23:15 PM12/14/11
to g3d-...@googlegroups.com
Well, you are creating a GThread referenence in the constructor which is obviously being destroyed when it goes out of scope at the end of the constructor.
 
I thought that running() was returning false because the operating system had not created the thread yet.  If you check for not completed, then it should wait until the thread exits.
 
You need to use a debugger and figure out why it's not waiting for the thread to complete.  Put break points in the thread's main procedure.  Put breakpoints at the end of the constructor.  At least add debug output to track what the state of the GThread reference is before during and after the while() loop.
 
You should also use the debugger to confirm when the GThread reference is being destroyed by checking the callstack.
 
corey

Vitaly Shevtsov

unread,
Dec 15, 2011, 1:49:46 PM12/15/11
to g3d-...@googlegroups.com
Good day, Corey!

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 Shevtsov

unread,
Dec 15, 2011, 1:52:12 PM12/15/11
to g3d-...@googlegroups.com
I forgot to mention that (thread->completed() == false) really works. Thanks

--
Vitaly

Corey Taylor

unread,
Dec 15, 2011, 11:10:28 PM12/15/11
to g3d-...@googlegroups.com
I wouldn't expect MeshAlg::generateGrid() to cause GThread to malfunction.
 
What is the actual callstack when the assert is triggered?
 
corey

Vitaly Shevtsov

unread,
Dec 16, 2011, 11:43:41 PM12/16/11
to g3d-...@googlegroups.com
is it?

> 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

Vitaly Shevtsov

unread,
Dec 16, 2011, 11:53:10 PM12/16/11
to g3d-...@googlegroups.com
it stumbles on "msvcr100.dll!memcpy(unsigned char * dst, unsigned char

Vitaly Shevtsov

unread,
Dec 16, 2011, 11:56:18 PM12/16/11
to g3d-...@googlegroups.com
it stumbles on "msvcr100.dll!memcpy(unsigned char * dst, unsigned char
* src, unsigned long count)  Line 313   Asm"

memcpy.asm:313
mov [edi+ecx*4-12],eax ;U - put dword into destination

--
Vitaly

Vitaly Shevtsov

unread,
Dec 17, 2011, 11:33:55 AM12/17/11
to g3d-...@googlegroups.com
(sigh) :)

I've found the issue. Sorry for misleading you. I'm confused with pointers

--
Vitaly

Corey Taylor

unread,
Dec 17, 2011, 4:02:21 PM12/17/11
to g3d-...@googlegroups.com

Not a problem.  Been too busy myself to really help.  I wont be around to answer emails for a couple weeks.

Happy Holidays!

corey

Vitaly Shevtsov

unread,
Dec 18, 2011, 5:03:27 AM12/18/11
to g3d-...@googlegroups.com
Thanks! :) Happy holidays to you
Reply all
Reply to author
Forward
0 new messages