Crash when Veto()ing wxSpinEvent 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
Kerry
Experienced Solver
Experienced Solver
Posts: 58
Joined: Fri Mar 07, 2008 5:44 pm

Crash when Veto()ing wxSpinEvent

Post by Kerry »

Hello all,

I'm having an issue when attempting to veto a wxSpinEvent for a wxSpinCtrl. I'm running wx3.0.0 under MSW. If I don't attempt to veto the event, everything works fine, but when I do veto, MSVC++ 2010 complains with "Run-Time Check Failure #2 - Stack around the variable 'event' was corrupted." this happens on the call to event.Veto().

Interestingly, there's no crash if I use wx2.8.12. The veto doesn't work, though (event occurs despite the veto).

Any ideas?

Thanks,

Kerry
User avatar
doublemax
Moderator
Moderator
Posts: 19160
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: Crash when Veto()ing wxSpinEvent

Post by doublemax »

Check if you can modify one of the wxWidgets samples to reproduce the problem.
Use the source, Luke!
Kerry
Experienced Solver
Experienced Solver
Posts: 58
Joined: Fri Mar 07, 2008 5:44 pm

Re: Crash when Veto()ing wxSpinEvent

Post by Kerry »

Very easily. In the "widgets" sample, in SpinBtnWidgetsPage::OnSpinCtrl() insert this (at line 573):

Code: Select all

	if (event.GetPosition() == 3)
	{
		event.Veto();
		wxLogMessage(wxT("Change Vetoed"));
		return;
	}
When running the sample, choose Spin under the Native list in the tree control, then on the far right pane, where the three sample controls are, click the up arrow on the wxSpinCtrl. Observe the value changing from 0 to 1, then 2, then the crash described in my first post when you expect 3.

-Kerry
User avatar
doublemax
Moderator
Moderator
Posts: 19160
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: Crash when Veto()ing wxSpinEvent

Post by doublemax »

I can reproduce the problem and i believe it's a bug in wxWidgets. I'll research some more and open a bug report if necessary.
Use the source, Luke!
User avatar
doublemax
Moderator
Moderator
Posts: 19160
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: Crash when Veto()ing wxSpinEvent

Post by doublemax »

I created a bug report here: http://trac.wxwidgets.org/ticket/16948
Use the source, Luke!
Kerry
Experienced Solver
Experienced Solver
Posts: 58
Joined: Fri Mar 07, 2008 5:44 pm

Re: Crash when Veto()ing wxSpinEvent

Post by Kerry »

Thanks for the help.

I've found that an OK work-around is to define a handler for EVT_TEXT for the spin control - of course there's no Veto(), but I can set the value to a valid value to reject the user's change. Doing this in the EVT_SPIN and EVT_SPINCTRL handlers is not enough: It sets the value properly the first time I click the spin button towards the invalid value, but the second click still results in a changed value.

-Kerry
User avatar
doublemax
Moderator
Moderator
Posts: 19160
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: Crash when Veto()ing wxSpinEvent

Post by doublemax »

The issue of stack corruption is fixed now, but calling Veto() still won't work. This behavior is not implemented on any platform.

FWIW, i don't think it makes much sense from a UI point of view that individual values are not allowed when using a spin control.
Use the source, Luke!
Kerry
Experienced Solver
Experienced Solver
Posts: 58
Joined: Fri Mar 07, 2008 5:44 pm

Re: Crash when Veto()ing wxSpinEvent

Post by Kerry »

Yes, you're right. I actually needed to change the allowable minimum value depending on the selections made in some other controls, and for some reason I was trying to handle this with a veto instead of a call to SetMin(). It turns out using SetMin() is a much better solution.

Thanks for pointing out my terrible design #-o

-Kerry
Post Reply