Size Event giving terrible problems... Hopefuly easy to fix 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.
parad0x13
Experienced Solver
Experienced Solver
Posts: 79
Joined: Tue Jan 06, 2009 3:09 am

Size Event giving terrible problems... Hopefuly easy to fix

Post by parad0x13 »

I have the code:

Code: Select all

EVT_SIZE(RenderFrm::OnSize)

void RenderFrm::OnSize(wxSizeEvent& event)
{
	RenderCanvasLink->CenterOnParent();
}
and I am getting an 'Access violation reading location' error!

If I use a different type of event such as:

Code: Select all

EVT_CLOSE(RenderFrm::OnClose)

void RenderFrm::OnClose(wxCommandEvent& event)
{
	RenderCanvasLink->CenterOnParent();
}
I get absolutely no problems... I don't know why the Size Event is not allowing memory to be read...

Does anyone know how to rectify this problem?

- Thank You
User avatar
Disch
Experienced Solver
Experienced Solver
Posts: 99
Joined: Wed Oct 17, 2007 2:01 am

Post by Disch »

Make sure RenderCanvasLink is a valid pointer. It's possible Size events are sent before the window becomes initially visible, if you're not creating your RenderCanvasLink object before then, you'll be trying to dereference a bad pointer.

To confirm, you can try zeroing the pointer during RenderFrm's ctor and only dereference it if it's nonzero:

Code: Select all

RenderFrm::RenderFrm(...) : wxFrame(...)
{
  RenderCanvasLink = NULL;
  ...
}

void RenderFrm::OnSize(wxCommandEvent& event)
{
  if(RenderCanvasLink != NULL)
    RenderCanvasLink->CenterOnParent();
}
parad0x13
Experienced Solver
Experienced Solver
Posts: 79
Joined: Tue Jan 06, 2009 3:09 am

Post by parad0x13 »

Yesh, this fixed my problem : )

Thank you very much! That would have been a good... 2 hours of troubleshooting lol

Again thank you
Auria
Site Admin
Site Admin
Posts: 6695
Joined: Thu Sep 28, 2006 12:23 am

Post by Auria »

Please mark the post as accepted to give credits to the person who helped you and close the question. I did it for you this time :)

Thanks