|
===<高手留意>=== java通过jni调用osg的问题
目的:java通过jni调用osg的动态库,让osg在java的窗口中绘制三维图像。
我将osg程序编译成动态链接库,然后让java通过jni的方式调用该dll,
当执行到 m_RenderSurface->realize() 的时候java端抛出异常:
请问有人通过这种方法实现过吗?请高手指教!
java异常打印:
#
# An unexpected error has been detected by HotSpot Virtual Machine:
#
# EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x02dfbf71, pid=5652, tid=2516
#
# Java VM: Java HotSpot(TM) Client VM (1.4.2_11-b06 mixed mode)
# Problematic frame:
# C [awt.dll+0x7bf71]
#
# An error report file with more information is saved as hs_err_pid5652.log
#
# If you would like to submit a bug report, please visit:
# http://java.sun.com/webapps/bugreport/crash.jsp
#
=====================================
osg代码:
void COSGFrame::InitOsg()
{
// create the window to draw to.
m_RenderSurface = new Producer::RenderSurface;
m_RenderSurface->setWindow(this->m_hWnd);
m_RenderSurface->useBorder(false);
m_RenderSurface->setInputRectangle( Producer::RenderSurface::InputRectangle(0.0,0.5,0.0,1.0));
m_RenderSurface->fullScreen(true);
// create the view of the scene.
m_SceneView = new osgUtil::SceneView;
m_SceneView->setDefaults();
// do the set up of the DatabasePager...
// create the database pager via the osgDB::Registry
m_DatabasePager = osgDB::Registry::instance()->getOrCreateDatabasePager();
// set wether the DatabasePager thread should be blocked while the scene graph is being used to render a frame
// setting frame block to true can help achieve constant frame rates on single CPU systems.
m_DatabasePager->setUseFrameBlock(false);
// need to register the DatabasePager with the SceneView's CullVisitor so it can pass on request
// for files to be loaded.
m_SceneView->getCullVisitor()->setDatabaseRequestHandler(m_DatabasePager);
//////////OnShow
m_RenderSurface->realize();//调用到该处出错!!!!!
m_bRenderSurfaceRealized = TRUE;
// The producer keyboard&mouse handler
m_KBM = new Producer::KeyboardMouse(m_RenderSurface.get());
// create a KeyboardMouseCallback to handle the mouse events within this applications
m_KBMCallback = new MFCKeyboardMouseCallback(m_SceneView.get());
//onsize
RECT rect;
::GetWindowRect(this->m_hWnd,&rect);
float cx=rect.right-rect.left;
float cy=rect.bottom-rect.top;
float aspectRatio = static_cast<float>(cx)/static_cast<float>(cy);
osg::Matrix projection;
projection.makePerspective(50.0f,aspectRatio,0.1f,50000.0f);
m_SceneView->setProjectionMatrix(projection);
osg::Group* m_rootNode = new osg::Group;
osg::MatrixTransform* m_ViewNode = new osg::MatrixTransform;
m_rootNode->addChild( m_ViewNode );
m_SceneView->setViewport(0,0,m_RenderSurface->getWindowWidth(),m_RenderSurface->getWindowHeight());
m_RenderSurface->makeCurrent();
//oninitupdate
char path[100];
strcpy(path,"e:\\test.osg");
osg::ref_ptr<osg::Node> model = osgDB::readNodeFile((LPCSTR)path);
m_pPat=new osg:ositionAttitudeTransform;
m_pPat->addChild(model.get());
if (model.get())
{
m_SceneView->setSceneData(m_pPat);
// register any PagedLOD that need to be tracked in the scene graph
m_DatabasePager->registerPagedLODs(m_SceneView->getSceneData());
// record the timer tick at the start of rendering.
m_StartTick = osg::Timer::instance()->tick();
m_uiFrameNum = 0;
m_KBMCallback->home();
}
m_bModelLoaded = TRUE;
} |
|