查看: 2131|回复: 1

===<高手留意>=== java通过jni调用osg的问题

[复制链接]

该用户从未签到

发表于 2010-7-5 19:13:54 | 显示全部楼层 |阅读模式
===<高手留意>===     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;
}

该用户从未签到

发表于 2010-7-6 22:02:10 | 显示全部楼层
说实话我真的没有接触过OSG与Java的嵌合,以前有一个osgJava工程,不过后来好像一直没有更新过。不知道楼主能否抽时间介绍一下JNI中调用OSG库的方法?
您需要登录后才可以回帖 登录 | 注册

本版积分规则

OSG中国官方论坛-有您OSG在中国才更好

网站简介:osgChina是国内首个三维相关技术开源社区,旨在为国内更多的技术开发人员提供最前沿的技术资讯,为更多的三维从业者提供一个学习、交流的技术平台。

联系我们

  • 工作时间:09:00--18:00
  • 反馈邮箱:1315785073@qq.com
快速回复 返回顶部 返回列表