|
代码如下:
int main()
{
osg::ref_ptr<osg::Group>root = new osg::Group;
osg::ref_ptr <osg::Node>spaceship = osgDB::readNodeFile("spaceship.osgt");
osg::ref_ptr <osgViewer::Viewer>viewer = new osgViewer::Viewer;
root->setDataVariance(osg::Object: YNAMIC);
viewer->addEventHandler(new osgViewer::StatsHandler);
root->addChild(spaceship.get());
viewer->setSceneData(root.get());
viewer->setCameraManipulator(new CSouth());
hMutex = CreateMutex(NULL, FALSE, NULL);
while (viewer)
{
HANDLE hThread1;
hThread1 = CreateThread(NULL, 0, Function, NULL, 0, NULL);
CloseHandle(hThread1);
viewer->run();
Sleep(2000);
}
}
DWORD WINAPI Function(LPVOID lpParameter)
{
string sql;
CADO record;
_RecordsetPtr m_pRecordset;
sql = "select * from navigation";
_bstr_t bstr_t(sql.c_str());
m_pRecordset = record.GetRecordset(bstr_t);
while (1)
{
WaitForSingleObject(hMutex, INFINITE);
while (!m_pRecordset->rsEOF)
{
float x = m_pRecordset->GetCollect("position_x");
float y = m_pRecordset->GetCollect("position_y");
float dis = sqrt((eyepos.x() - x)*(eyepos.x() - x) + (eyepos.y() - y)*(eyepos.y() - y));
if (dis < 300)
{
CStringW cs;
_variant_t va = m_pRecordset->GetCollect("nodename");
cs = va.bstrVal;
CStringA stra(cs.GetBuffer(0));
nodename = stra.GetBuffer(0);
stra.ReleaseBuffer();
std::cout << nodename << endl;
osg::ref_ptr <osg::Node>node = osgDB::readNodeFile(nodename);
if (node)
{
root->addChild(node.get());
}
}
m_pRecordset->MoveNext();
}
ReleaseMutex(hMutex);
}
record.ExitConnect();
return 0;
}
用新开的线程读取SQL SERVER数据库,模型的信息保存在数据库中,能够读取并将模型加入到场景中,但是立即就出现了上述错误,不知道是哪里出了问题,这个问题已经折磨我三四天了,希望高人看到后能够指点一二,不胜感激! |
|