我要发帖 回复

中级会员

11

主题

341

积分

0

专家分

兴趣点(最多三项):

视景仿真

私信
发表时间 : 2011-8-31 22:54:55 | 浏览 : 1400    评论 : 7
建立了一个最基本的基于线程的VP单文档程序框架,什么define(),configure(),run()都是按照最小系统弄的,添加了WM_CREATE WM_SIZE两个消息,在没有对WM_SIZE消息不写任何代码的情况下运行正常。但是此时如果单击此单文档框架,其最大化后,vp的那个窗口只占右上角的一部分,于是加入一下代码:
void xxxxx::OnSize(UINT nType, int cx, int cy)
{
    CView::OnSize(nType, cx, cy);
    vpWindow *vpWin = *vpWindow::begin();
    vpWin->setSize(cx, cy);
}
mfc_vp.exe 中的 0x005272d7 (vsgu2_0D.dll) 处未处理的异常: 0xC0000005: 读取位置 0x00000000 时发生访问冲突 。
其他代码如下:
UINT vpWorkThread(LPVOID pParam)
{
        Cmfc_vpView* pView = (Cmfc_vpView*)pParam;
        vp::initialize(__argc, __argv);       
                 
        pView->define();
        pView->configure();
        pView->run();
//        pView->unconfigure();
        vp::shutdown();
        return 1;
}
int Cmfc_vpView::define(void)
{
    int nRet = 0;
    char *pszName = ".\\vp_timer.acf";
    if (__argc <= 1)
        nRet = vpKernel::instance()->define(pszName);
    else
        nRet = vpKernel::instance()->define(__argv[1]);
        return nRet;
}
int Cmfc_vpView::configure(void)
{
int nRet = vpKernel::instance()->configure();
assert(vpWindow::size() != 0);
vpWindow *vrWin = *vpWindow::begin();
vrWin->setParent(m_hWnd);
vrWin->setBorderEnable(false);//去掉边框
vrWin->setFullScreenEnable( true );//填满view       
return nRet;
}
void Cmfc_vpView::run(void)
{
        while ( vpKernel::instance()->beginFrame() != 0 )
        {
                vpKernel::instance()->endFrame();
        }
}


int Cmfc_vpView::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
        if (CView::OnCreate(lpCreateStruct) == -1)
                return -1;

        // TODO:  在此添加您专用的创建代码
//        AfxBeginThread(vpWorkThread,this);
        return 0;
}

最近VR访客

撒旦狂魔 评论于2011-8-31 22:56:18
就是加入那个WM_SIZE那段代码会出现访问冲突,苦思不得不得其解。。。
撒旦狂魔 评论于2011-9-1 21:51:47
自己再顶一下~~
hithyy 评论于2011-10-22 22:31:40
onsize发生的时候要保证vp已经运行起来,要能够得到有效的vpwindow
buf265 评论于2011-10-22 23:08:31
楼上正解,在vpWin->setSize(cx, cy);之前检查vpWin是否指向有效的vpWindow
cyscsharp 评论于2011-11-2 14:42:42
本帖最后由 cyscsharp 于 2011-11-2 02:44 PM 编辑

一楼的哥哥,我也遇到同你一样的错误、
  vpWindow *vpWin = *vpWindow::begin();
        static vpWindow* tmp=vpWin;

        if(vpWin!=NULL)
        {
                               //程序能进入到这里面来,说明vpWin不为null
                // set this MFC View window as the parent of the Vega Prime window
                vpWin->setParent(m_hWnd);//可是这句话却报错,内存冲突,为何?
                //vpWin->setParent(this->GetSafeHwnd());

                // remove the Vega Prime border (use MFC parent window border instead)
                vpWin->setBorderEnable(false);

                // let MFC parent window determine our size by filling the MFC parent
                // window frame
                vpWin->setFullScreenEnable(true);
        }

我就想实现把VP窗口嵌入到MFC中
这是vp_mfcView.cpp的完整代码:


// mfcView.cpp : implementation of the CMFCView class
//

#include "stdafx.h"
#include "vp_mfc.h"

#include "vp_mfcDoc.h"
#include "vp_mfcView.h"


// START: Vega Prime - Includes


//              NOTE: Vega Prime includes MUST be placed BEFORE
//                    the line of code '#define new DEBUG_NEW' because
//                    of a conflict created by redefining DEBUG_NEW.

//#include <vp.h>
//#include <vpKernel.h>
//#include <vpWindow.h>

#include <vuAllocArray.h>
#include <vuAllocTracer.h>
#include <vrGeometry.h>
#include <vrLight.h>
#include <vrMode.h>
#include <vsGeometry.h>
#include <vsRenderStrategy.h>
#include <vpApp.h>
#include <vpObject.h>
#include <vrMaterial.h>
#include <iostream>


// END: Vega Prime - Includes

/**
* NOTE: do NOT define DEBUG_NEW when compiling with MFC.
* This macro redefines operator new() - a very bad thing by itself.
* In addition to that, you may get the following warning from
* the compiler:
* warning C4291: 'void *myClass::operator new(size_t,const char *,uint)' :
* no matching operator delete found; memory will not be freed if initialization throws an exception
*/
//#ifdef _DEBUG
//#define new DEBUG_NEW
//#undef THIS_FILE
//static char THIS_FILE[] = __FILE__;
//#endif


/////////////////////////////////////////////////////////////////////////////
// CMFCView

IMPLEMENT_DYNCREATE(CMFCView, CView)

BEGIN_MESSAGE_MAP(CMFCView, CView)
    //{{AFX_MSG_MAP(CMFCView)
    ON_WM_CREATE()
    ON_WM_TIMER()
    ON_WM_SIZE()
    //}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CMFCView construction/destruction

CMFCView::CMFCView()
{
    // TODO: add construction code here

}

CMFCView::~CMFCView()
{


    // START: Vega Prime - Shutdown
   
    // Notify VP that we want to end frame loop
    vpKernel::instance()->breakFrameLoop();

    // Allow VP to exit from frame loop
    int frameNum = vpKernel::instance()->beginFrame();
    assert(frameNum == 0);

    int result; // vsgu::SUCCESS or vsgu::FAILURE

    result = vpKernel::instance()->unconfigure();
    assert(result == vsgu::SUCCESS);
   
    result = vp::shutdown();
    assert(result == vsgu::SUCCESS);

    // END: Vega Prime - Shutdown


}

BOOL CMFCView::PreCreateWindow(CREATESTRUCT& cs)
{
    // TODO: Modify the Window class or styles here by modifying
    //  the CREATESTRUCT cs

    return CView::PreCreateWindow(cs);
}

/////////////////////////////////////////////////////////////////////////////
// CMFCView drawing

void CMFCView::OnDraw(CDC* pDC)
{
    CMFCDoc* pDoc = GetDocument();
    ASSERT_VALID(pDoc);
    // TODO: add draw code for native data here
}

/////////////////////////////////////////////////////////////////////////////
// CMFCView diagnostics

#ifdef _DEBUG
void CMFCView::AssertValid() const
{
    CView::AssertValid();
}

void CMFCView::Dump(CDumpContext& dc) const
{
    CView::Dump(dc);
}

CMFCDoc* CMFCView::GetDocument() // non-debug version is inline
{
    ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CMFCDoc)));
    return (CMFCDoc*)m_pDocument;
}
#endif //_DEBUG


/////////////////////////////////////////////////////////////////////////////
// CMFCView message handlers

int CMFCView::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
    if (CView::OnCreate(lpCreateStruct) == -1)
        return -1;

    // TODO: Add your specialized creation code here

   
    // START: Vega Prime - Initialization

        static int ac=__argc;
        char* cc="E:\workspace\workProject\MFCVP\new\vp_Mars_vs2005\release\vp_mfc.exe";
        static char** av=__argv;


    int result; // vsgu::SUCCESS or vsgu::FAILURE
   

    //result = vp::initialize(__argc, __argv);//debug用
        result = vp::initialize(__argc, &cc);//release用

        static int i=result;

        
    assert(result == vsgu::SUCCESS);

    // set acf file
    char* acfFile="vp_mfc.acf";

   /* if (__argc <= 1)
        acfFile = "vp_mfc.acf";
    else
        acfFile = __argv[1];*/

    // load acf file
    result = vpKernel::instance()->define(acfFile);
    assert(result == vsgu::SUCCESS);

        
    // configure Vega Prime
    result = vpKernel::instance()->configure();
    assert(result == vsgu::SUCCESS);


    // assuming at least one window in acf
    assert(vpWindow::size() != 0);

    // get the first Vega Prime window
    vpWindow *vpWin = *vpWindow::begin();
        static vpWindow* tmp=vpWin;

        if(vpWin!=NULL)
        {//程序确实能进来,说明vpWin不是NULL
                // set this MFC View window as the parent of the Vega Prime window
                vpWin->setParent(m_hWnd);//这里却报内存冲突,程序执行不下去了,为何冲突?
                //vpWin->setParent(this->GetSafeHwnd());

                // remove the Vega Prime border (use MFC parent window border instead)
                vpWin->setBorderEnable(false);

                // let MFC parent window determine our size by filling the MFC parent
                // window frame
                vpWin->setFullScreenEnable(true);
        }


    // We can force the Vega Prime window open by calling beginFrame/endFrame
   
    //   NOTE: OnActivateView requires the Vega Prime window open before it is
    //         called.  If it is not open, the Vega Prime window will never
    //         get focus and thus will not handle keyboard input.

    int frameNum = vpKernel::instance()->beginFrame();
    assert(frameNum != 0);

    result = vpKernel::instance()->endFrame();
    assert(result == vsgu::SUCCESS);



    // setup timer that updates frame

    //   NOTE: Timer messages (WM_TIMER) are low priority messages.  They
    //         are processed after all other messages have been processed.
    //         Updating frames this way makes the application more responsive
    //         at the expense of frame updates.

    // Timeout of 16 means send a WM_TIMER message at 60Hz.

    const int TIMER_ID = 1;
    int timeout = 16;
    int returnValue = SetTimer(TIMER_ID, timeout, NULL);   
    assert(returnValue == TIMER_ID);


    // END: Vega Prime - Initialization


    return 0;
}

void CMFCView::OnTimer(UINT nIDEvent)
{
    // TODO: Add your message handler code here and/or call default


    // START: Vega Prime - Frame Update


    int frameNum = vpKernel::instance()->beginFrame();
    assert(frameNum != 0);

    int result = vpKernel::instance()->endFrame();
    assert(result == vsgu::SUCCESS);


    // END: Vega Prime - Frame Update
  

    CView::OnTimer(nIDEvent);
}

void CMFCView::OnActivateView(BOOL bActivate, CView* pActivateView, CView* pDeactiveView)
{
    // TODO: Add your specialized code here and/or call the base class

    CView::OnActivateView(bActivate, pActivateView, pDeactiveView);


    // START: Vega Prime - Set Focus

   
    // NOTE: Make sure base class OnActivateView is called BEFORE we set the
    //       focus.  Otherwise, the MFC Parent window will take the focus
    //       from the Vega Prime window.  The window with the focus receives
    //       keyboard input.

    // if activating this view...
    if(bActivate) {

        // get the first Vega Prime window
        vpWindow *vpWin = *vpWindow::begin();

        // set the focus
        HWND hVPWnd = vpWin->getWindow();
        assert(::IsWindow( hVPWnd ) == TRUE);
        ::SetFocus(hVPWnd);
    }


    // END: Vega Prime - Set Focus
   

}

void CMFCView::OnSize(UINT nType, int cx, int cy)
{
    CView::OnSize(nType, cx, cy);
   
    // TODO: Add your message handler code here
   
   
    // START: Vega Prime - Set Size

    // get the first Vega Prime window
    vpWindow *vpWin = *vpWindow::begin();

    // set size of Vega Prime window
    vpWin->setSize(cx, cy);


    // END: Vega Prime - Set Size


}

但上面的代码在debug下却正常,只在release下才报上面的内存冲突
请高手指点
感谢

gongzixiaobai 评论于2012-4-5 15:42:20
hithyy 发表于 2011-10-22 10:31 PM
onsize发生的时候要保证vp已经运行起来,要能够得到有效的vpwindow

确实是这样。谢谢

手机版|VR开发网 统计 津ICP备18009691号
网安备12019202000257

GMT+8, 2022-8-12 11:34 AM

返回顶部