查看: 1102|回复: 3

ActiveX控件的问题。。

[复制链接]

该用户从未签到

发表于 2011-8-21 21:39:23 | 显示全部楼层 |阅读模式
array大哥,我是借鉴你的那个OSG跟ActiveX控件结合的例子做了修改,但是我在IE9.0下调试是可以通过,但是在关闭页面时会弹出一个异常出来,如果我读的是网络上的图片时就会出现这个问题,如果读的是本地的图片就不会出现这个异常,不知道您有没有遇到这种问题,下面是我抛出的异常:
QQ截图20110821212818.jpg
我大概程序流程是:网络上js函数调用控件里面的函数,将一些图片的URL传入控件,然后将它显示,如果有单击的话,传一些信息到JS函数,下面的主要代码:
接口函数:

  1. void CpictureCtrl::input(BSTR m_str)
  2. {
  3. _bstr_t bstr_t(m_str);
  4. std::string str(bstr_t);
  5. mOSG->analysis(str);
  6. }
复制代码

我在创建的时候是这样设置:

  1. int CpictureCtrl::OnCreate(LPCREATESTRUCT lpCreateStruct)
  2. {
  3. if (CSafeOleControl::OnCreate(lpCreateStruct) == -1)
  4.   return -1;
  5. // TODO:  在此添加您专用的创建代码
  6. mOSG = new cOSG(m_hWnd);
  7. mOSG->Init();
  8. mThreadHandle = (HANDLE)_beginthread(&cOSG::Render, 0, mOSG);
  9. return 0;
  10. }
复制代码

下面是关于cOSG这个类的主要方法:

  1. cOSG::cOSG(HWND hWnd) :
  2. m_hWnd(hWnd)
  3. {
  4. // 创建一个视图
  5. mViewer = new osgViewer::Viewer();
  6. m_clearnode = new osg::ClearNode;
  7. mRoot  = new osg::Group;
  8. m_width = 0;
  9. m_height = 0;
  10. }
  11. cOSG::~cOSG()
  12. {
  13. mViewer->setDone(true);
  14. Sleep(1000);
  15. mViewer->stopThreading();
  16. if(mViewer)
  17.   delete mViewer;
  18. }
  19. void cOSG::analysis(std::string name)
  20. {
  21. int i, start, end, j;
  22. int num = 0;
  23. std::string str, str1, str2;
  24. if(name == "")
  25.   return;
  26. j = name.find(',');
  27. assert(j);
  28. str = name.substr(0, j);
  29. num = StringToInt(str, 0, j);
  30. mPicture->setNum(num);
  31. for(i = 0; i < num; i++)
  32. {
  33.   //id号
  34.   start = j + 1;
  35.   end = name.find(',', start);
  36.   if(end == -1)
  37.    return;
  38.   str = name.substr(start, end - start);
  39.    
  40.   //图片name
  41.   start = end + 1;
  42.   end = name.find(',', start);
  43.   if(end == -1)
  44.    return;
  45.   str1 = name.substr(start, end - start);
  46.   //图片url
  47.   start = end + 1;
  48.   end = name.find(',', start);
  49.   if(i == num - 1)
  50.   {
  51.    str2 = name.substr(start, name.size());
  52.   }
  53.   else
  54.   {
  55.    if(end == -1)
  56.     return;
  57.    str2 = name.substr(start, end - start);
  58.   }
  59.   j = end;
  60.   mPicture->setName(i, str, str1, str2);
  61. }
  62. mPicture->begin(mRoot.get());
  63. mViewer->getCameraManipulator()->computeHomePosition();
  64. mViewer->getCameraManipulator()->home( 0.0 );
  65. }
  66. int cOSG::StringToInt(std::string str, int start, int end)
  67. {
  68. int num = 0;
  69. int j = 1;
  70. for(int i = start; i < end; i++)
  71. {
  72.   num = num * j + (str[i] - '0');
  73.   j = j * 10;
  74. }
  75. return num;
  76. }

  77. void cOSG::InitCameraConfig(void)
  78. {
  79. // Local Variable to hold window size data
  80. RECT rect;
  81. // Add a Stats Handler to the viewer
  82. // mViewer->addEventHandler(new osgViewer::StatsHandler);  
  83. // Get the current window size
  84. // Get the current window size
  85. ::GetWindowRect(m_hWnd, &rect);
  86. // Init the GraphicsContext Traits
  87. osg::ref_ptr<osg::GraphicsContext::Traits> traits = new osg::GraphicsContext::Traits;
  88. // Init the Windata Variable that holds the handle for the Window to display OSG in.
  89. osg::ref_ptr<osg::Referenced> windata = new osgViewer::GraphicsWindowWin32::WindowData(m_hWnd);
  90. // Setup the traits parameters
  91. traits->x = 0;
  92. traits->y = 0;
  93. /*traits->width = rect.right - rect.left;
  94. traits->height = rect.bottom - rect.top;*/
  95. traits->width = 1440;
  96. traits->height = 768;
  97. traits->windowDecoration = false;
  98. traits->doubleBuffer = true;
  99. traits->sharedContext = 0;
  100. traits->setInheritedWindowPixelFormat = true;
  101. traits->inheritedWindowData = windata;
  102. // Create the Graphics Context
  103. osg::ref_ptr<osg::GraphicsContext> gc = osg::GraphicsContext::createGraphicsContext(traits.get());
  104. if(gc.valid())
  105. {
  106.   //osg::notify(osg::INFO)<<"GraphicsWindow has been created successfully."<<std::endl;
  107.   //清除窗口颜色及清除颜色和深度缓冲
  108.   gc->setClearColor(osg::Vec4f(0.2f,0.2f,0.6f,1.0f));
  109.   gc->setClearMask(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  110. }
  111. else
  112. {
  113.   //osg::notify(osg::NOTICE)<<" GraphicsWindow has not been created successfully."<<std::endl;
  114. }
  115. double fovy,aspectRatio,zNear,zFar;
  116. mViewer->getCamera()->getProjectionMatrixAsPerspective(fovy,aspectRatio,zNear,zFar);
  117. double newAspectRatio = double(traits->width)/double(traits->height);
  118. double aspectRatioChange = newAspectRatio/aspectRatio;
  119. mViewer->getCamera()->setClearColor(osg::Vec4(0.8, 0.8, 0.8, 1.0));
  120. if(aspectRatioChange != 1.0)
  121. {
  122.   //设置投影矩阵
  123.   mViewer->getCamera()->getProjectionMatrix() *= osg::Matrix::scale(1.0/aspectRatioChange,1.0,1.0);
  124. }
  125. // Set the viewport for the Camera
  126. mViewer->getCamera()->setViewport(new osg::Viewport(traits->x, traits->y, traits->width, traits->height));
  127. //设置图形环境
  128. mViewer->getCamera()->setGraphicsContext(gc.get());
  129. mViewer->setCameraManipulator(new osgGA::TrackballManipulator);
  130. mViewer->setThreadingModel(osgViewer::Viewer::SingleThreaded);
  131. // Add the Camera Manipulator to the Viewer
  132. mViewer->setCameraManipulator(new Manipulator);
  133. mViewer->addEventHandler(new Pickhandle);
  134. ////
  135. mPicture = new osgPicture(traits->width, traits->height);
  136. //analysis("1,1,name,http://192.168.1.105:8022/Artwork/ArtImg/花鸟画.jpg");
  137. osgUtil::Optimizer optimizer;
  138. optimizer.optimize(mRoot);
  139. // Set the Scene Data
  140. mViewer->setSceneData(mRoot.get());
  141. // Realize the Viewer
  142. mViewer->realize();
  143. }
复制代码

各位能不能帮我看一下,这个问题一直困恼着我。。在IE系列的浏览器下关闭的时候都会弹出一个异常。。。

该用户从未签到

发表于 2011-8-22 08:41:02 | 显示全部楼层
调试吧。。。然后观察堆栈的值。。。

该用户从未签到

 楼主| 发表于 2011-8-22 08:43:35 | 显示全部楼层
好的。看来只有多调试,才能发现问题的所在了。。

该用户从未签到

发表于 2011-10-22 12:42:14 | 显示全部楼层
回复 3# sumingnan


    是不是因为加载的模型过大,渲染过程中加载导致加载失败。你自己定义个线程,当加载模型的时候关闭渲染线程,加载函数结束后再开启。你试试。。。。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

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

联系我们

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