abstract question about acces violation Topic is solved

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
schoonmoeder
Knows some wx things
Knows some wx things
Posts: 36
Joined: Thu Feb 01, 2007 12:03 pm
Location: netherlands

abstract question about acces violation

Post by schoonmoeder » Wed Feb 28, 2007 10:06 am

hi all,

i have some trouble with acces violations and this happend to me more than offen.

some code giving me the latest error.

Code: Select all

bool wxOsgApp::OnInit()
{
    // Create the main frame window
    MainFrame *frame = new MainFrame(NULL, wxT("wxWidgets OSG Sample"),
        wxDefaultPosition, wxDefaultSize);

	// create osg canvas
	//	- initialise
	OsgGLCanvas *canvas = new OsgGLCanvas(frame, wxID_ANY, wxDefaultPosition,
        wxSize(200, 200), wxSUNKEN_BORDER);
	canvas->init("cow.osg");
    frame->SetCanvas(canvas);
	
    /* Show the frame */
    frame->Show(true);

    return true;
}
the line canvas->init is in my eye's the problem but error is still not here.

Code: Select all

bool OsgGLCanvas::init(const std::string &filename)
{   
	// load the scene.
    osg::ref_ptr<osg::Node> loadedModel = osgDB::readNodeFile("cow.osg");
    if (!loadedModel)
    {
        return false;
    }

	// create the view of the scene.
	viewer_ = new osgViewer::SimpleViewer;
    viewer_->setSceneData(loadedModel.get());
    viewer_->setCameraManipulator(new osgGA::TrackballManipulator);

	return true;
}
think by now the viewer would not be a error any more. but here comes the error part

Code: Select all

void OsgGLCanvas::OnSize(wxSizeEvent& event)
{
    // this is also necessary to update the context on some platforms
      wxGLCanvas::OnSize(event);

    // set GL viewport (not called by wxGLCanvas::OnSize on all platforms...)
      int width, height;
      GetClientSize(&width, &height);

      // update the window dimensions, in case the window has been resized.
      viewer_->getEventQueue()->windowResize(0, 0, width, height);
}
the line that uses viewer_ is giving an error.
for making the picture whole viewer_ i declared in the h file

Code: Select all

class OsgGLCanvas: public wxGLCanvas
{
public:
    OsgGLCanvas(wxWindow *parent, wxWindowID id = wxID_ANY,
        const wxPoint& pos = wxDefaultPosition,
        const wxSize& size = wxDefaultSize, long style = 0,
        const wxString& name = wxT("TestGLCanvas"));

    ~OsgGLCanvas();

	bool init(const std::string &filename);

    void OnPaint(wxPaintEvent& event);
    void OnSize(wxSizeEvent& event);
    void OnEraseBackground(wxEraseEvent& event);
    void OnMouse(wxMouseEvent &event);

private:
	osg::ref_ptr<osgViewer::SimpleViewer> viewer_;

    DECLARE_EVENT_TABLE()
};
i'm not aware of the fact if this is an wx error or a error caused by OSG
any help is apriciated.

thnx in advanced
Ewart ten Brink

ps the error message :P
First-chance exception at 0x00401885 in wxOsgCanvasTest.exe: 0xC0000005: Access violation reading location 0x00000004.
Unhandled exception at 0x00401885 in wxOsgCanvasTest.exe: 0xC0000005: Access violation reading location 0x00000004.

upCASE
Site Admin
Site Admin
Posts: 3176
Joined: Mon Aug 30, 2004 6:55 am
Location: Germany, Cologne

Post by upCASE » Wed Feb 28, 2007 10:23 am

Hi!
I'd say the error might be that OnSize is called before OsgGLCanvas::init(). Thus viewer_ doesn't exist yet leading to the crash when trying to access it.

Try setting viewer_ to NULL first and check in OnSize if it is NULL. If it is, don't access it. Once init() was called viewer_ will be created and the next call to OnSize can safely access it.
OS: OpenSuSE, Ubuntu, Win XP Pro
wx: svn
Compiler: gcc 4.5.1, VC 2008, eVC 4

"If it was hard to write it should be hard to read..." - the unknown coder
"Try not! Do. Or do not. There is no try." - Yoda

schoonmoeder
Knows some wx things
Knows some wx things
Posts: 36
Joined: Thu Feb 01, 2007 12:03 pm
Location: netherlands

Post by schoonmoeder » Wed Feb 28, 2007 12:19 pm

when i set

Code: Select all

if (view != 0){
 viewer_ code
}
i need to do it at paint and onsize. than it will start and give me a green screen(window with green background) problem is that when i try using my mouse the is aqain like what viewer_ isn't okay i give you aqain an error.

so im thinking of that the viewer_ pointer made in the h file isn't working good.

maybe you have another tip.

edit:
it looks like OsgGLCanvas::init is never called. because when i place a output messege there it is never showed to me.

Auria
Site Admin
Site Admin
Posts: 6695
Joined: Thu Sep 28, 2006 12:23 am
Contact:

Post by Auria » Wed Feb 28, 2007 6:36 pm

schoonmoeder wrote: edit:
it looks like OsgGLCanvas::init is never called. because when i place a output messege there it is never showed to me.
Then this is the issue - just call it ;)

schoonmoeder
Knows some wx things
Knows some wx things
Posts: 36
Joined: Thu Feb 01, 2007 12:03 pm
Location: netherlands

Post by schoonmoeder » Wed Feb 28, 2007 6:58 pm

there is a big problem with my osg. it's not working properly any more. it broke of the applet after i tryed to load a model.

so i have copyed the topic to a other forum that is for sog users.

thnx all
OS: Win XP Pro
wx: 2.8.0
Compiler: VC 8

Post Reply