Hi,
I need to load multiple OSG models of huge size (each model >60MB). So I wrote
a multi threaded program to read each model in a seperate thread. But I am
getting runtime error. Here I am giving code to read 2 models.
Code:
CRITICAL_SECTION cs;
struct ModelObj
{
Model *obj;
int id;
};
std::vector <HANDLE> T;
UINT ThreadProc1(LPVOID lpvoid)
{
ModelObj *temp = (ModelObj*)lpvoid;
temp->obj->trans[temp->id] = new osg::MatrixTransform;
//Transformation node
temp->obj->modelSwitch->addChild(temp->obj->trans[temp->id].get()); //Added to
model swithc
temp->obj->model[temp->id] =
osgDB::readNodeFile(temp->obj->fileNames[temp->id]); //Reading model
if(temp->obj->model[temp->id])
{
temp->obj->trans[temp->id]->addChild(temp->obj->model[temp->id].get());
}
return 0;
}
................
In main function
//model is a class
ModelObj *obj1;
obj1=new ModelObj;
obj1->id=0;
obj1->obj = &model;
ModelObj *obj2;
obj2=new ModelObj;
obj2->id=1;
obj2->obj = &model;
strcpy(model.fileNames[0],"1.osg");
strcpy(model.fileNames[1],"2.osg");
InitializeCriticalSection(&cs);
T.push_back (CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)
ThreadProc1, (LPVOID)obj1, CREATE_SUSPENDED, NULL));
T.push_back(CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE) ThreadProc1,
(LPVOID)obj2, CREATE_SUSPENDED, NULL));
ResumeThread(T[0]);
ResumeThread(T[1]);
WaitForMultipleObjects(2, &T[0], TRUE, INFINITE); //wait till all
models are red
DeleteCriticalSection(&cs);
std::cout<<"---------- R E A D ALL M O D E L S"<<std::endl;
...................
//here rendering frames
when I run this code i am getting runtime error. With out reading model code in
"ThreadProc1" function the behaviour is correct. That is main function is
waiting till all the threads are finished.
Do I need to take any care while reading OSG models.
Is there any other way to read OSG files faster?
Can you please guide to read OSG models in multi thread applicaiton.
...
Thank you!
Cheers,
Koduri
------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=48434#48434
_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org