|
array大哥,我是借鉴你的那个OSG跟ActiveX控件结合的例子做了修改,但是我在IE9.0下调试是可以通过,但是在关闭页面时会弹出一个异常出来,如果我读的是网络上的图片时就会出现这个问题,如果读的是本地的图片就不会出现这个异常,不知道您有没有遇到这种问题,下面是我抛出的异常:
我大概程序流程是:网络上js函数调用控件里面的函数,将一些图片的URL传入控件,然后将它显示,如果有单击的话,传一些信息到JS函数,下面的主要代码:
接口函数:
-
- void CpictureCtrl::input(BSTR m_str)
- {
- _bstr_t bstr_t(m_str);
- std::string str(bstr_t);
- mOSG->analysis(str);
- }
复制代码
我在创建的时候是这样设置:
-
- int CpictureCtrl::OnCreate(LPCREATESTRUCT lpCreateStruct)
- {
- if (CSafeOleControl::OnCreate(lpCreateStruct) == -1)
- return -1;
- // TODO: 在此添加您专用的创建代码
- mOSG = new cOSG(m_hWnd);
- mOSG->Init();
- mThreadHandle = (HANDLE)_beginthread(&cOSG::Render, 0, mOSG);
- return 0;
- }
复制代码
下面是关于cOSG这个类的主要方法:
-
- cOSG::cOSG(HWND hWnd) :
- m_hWnd(hWnd)
- {
- // 创建一个视图
- mViewer = new osgViewer::Viewer();
- m_clearnode = new osg::ClearNode;
- mRoot = new osg::Group;
- m_width = 0;
- m_height = 0;
- }
- cOSG::~cOSG()
- {
- mViewer->setDone(true);
- Sleep(1000);
- mViewer->stopThreading();
- if(mViewer)
- delete mViewer;
- }
- void cOSG::analysis(std::string name)
- {
- int i, start, end, j;
- int num = 0;
- std::string str, str1, str2;
- if(name == "")
- return;
- j = name.find(',');
- assert(j);
- str = name.substr(0, j);
- num = StringToInt(str, 0, j);
- mPicture->setNum(num);
- for(i = 0; i < num; i++)
- {
- //id号
- start = j + 1;
- end = name.find(',', start);
- if(end == -1)
- return;
- str = name.substr(start, end - start);
-
- //图片name
- start = end + 1;
- end = name.find(',', start);
- if(end == -1)
- return;
- str1 = name.substr(start, end - start);
- //图片url
- start = end + 1;
- end = name.find(',', start);
- if(i == num - 1)
- {
- str2 = name.substr(start, name.size());
- }
- else
- {
- if(end == -1)
- return;
- str2 = name.substr(start, end - start);
- }
- j = end;
- mPicture->setName(i, str, str1, str2);
- }
- mPicture->begin(mRoot.get());
- mViewer->getCameraManipulator()->computeHomePosition();
- mViewer->getCameraManipulator()->home( 0.0 );
- }
- int cOSG::StringToInt(std::string str, int start, int end)
- {
- int num = 0;
- int j = 1;
- for(int i = start; i < end; i++)
- {
- num = num * j + (str[i] - '0');
- j = j * 10;
- }
- return num;
- }
- void cOSG::InitCameraConfig(void)
- {
- // Local Variable to hold window size data
- RECT rect;
- // Add a Stats Handler to the viewer
- // mViewer->addEventHandler(new osgViewer::StatsHandler);
- // Get the current window size
- // Get the current window size
- ::GetWindowRect(m_hWnd, &rect);
- // Init the GraphicsContext Traits
- osg::ref_ptr<osg::GraphicsContext::Traits> traits = new osg::GraphicsContext::Traits;
- // Init the Windata Variable that holds the handle for the Window to display OSG in.
- osg::ref_ptr<osg::Referenced> windata = new osgViewer::GraphicsWindowWin32::WindowData(m_hWnd);
- // Setup the traits parameters
- traits->x = 0;
- traits->y = 0;
- /*traits->width = rect.right - rect.left;
- traits->height = rect.bottom - rect.top;*/
- traits->width = 1440;
- traits->height = 768;
- traits->windowDecoration = false;
- traits->doubleBuffer = true;
- traits->sharedContext = 0;
- traits->setInheritedWindowPixelFormat = true;
- traits->inheritedWindowData = windata;
- // Create the Graphics Context
- osg::ref_ptr<osg::GraphicsContext> gc = osg::GraphicsContext::createGraphicsContext(traits.get());
- if(gc.valid())
- {
- //osg::notify(osg::INFO)<<"GraphicsWindow has been created successfully."<<std::endl;
- //清除窗口颜色及清除颜色和深度缓冲
- gc->setClearColor(osg::Vec4f(0.2f,0.2f,0.6f,1.0f));
- gc->setClearMask(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
- }
- else
- {
- //osg::notify(osg::NOTICE)<<" GraphicsWindow has not been created successfully."<<std::endl;
- }
- double fovy,aspectRatio,zNear,zFar;
- mViewer->getCamera()->getProjectionMatrixAsPerspective(fovy,aspectRatio,zNear,zFar);
- double newAspectRatio = double(traits->width)/double(traits->height);
- double aspectRatioChange = newAspectRatio/aspectRatio;
- mViewer->getCamera()->setClearColor(osg::Vec4(0.8, 0.8, 0.8, 1.0));
- if(aspectRatioChange != 1.0)
- {
- //设置投影矩阵
- mViewer->getCamera()->getProjectionMatrix() *= osg::Matrix::scale(1.0/aspectRatioChange,1.0,1.0);
- }
- // Set the viewport for the Camera
- mViewer->getCamera()->setViewport(new osg::Viewport(traits->x, traits->y, traits->width, traits->height));
- //设置图形环境
- mViewer->getCamera()->setGraphicsContext(gc.get());
- mViewer->setCameraManipulator(new osgGA::TrackballManipulator);
- mViewer->setThreadingModel(osgViewer::Viewer::SingleThreaded);
- // Add the Camera Manipulator to the Viewer
- mViewer->setCameraManipulator(new Manipulator);
- mViewer->addEventHandler(new Pickhandle);
- ////
- mPicture = new osgPicture(traits->width, traits->height);
- //analysis("1,1,name,http://192.168.1.105:8022/Artwork/ArtImg/花鸟画.jpg");
- osgUtil::Optimizer optimizer;
- optimizer.optimize(mRoot);
- // Set the Scene Data
- mViewer->setSceneData(mRoot.get());
- // Realize the Viewer
- mViewer->realize();
- }
复制代码
各位能不能帮我看一下,这个问题一直困恼着我。。在IE系列的浏览器下关闭的时候都会弹出一个异常。。。 |
|