Another random crash

BlitzMax Forums/Brucey's Modules/Another random crash

plash(Posted 2008) [#1]
(FryDesigner) If the user selects a gadget, changes a property specific to that type of gadget, and selects a few other gadgets it will cause the application to crash at a random line (sometimes appending a new property or hiding/showing the category).

This only started happening once I added gadget specific properties to my grid (i.e. clearing a category of properties, but not removing the category from my grid or deleting the object - all of which I didn't do with general gadget properties before).

(only tested on Linux, so far)
http://files.filefront.com/fdwx+8+8+08+linux+beta1targz/;11415756;/fileinfo.html

To see for yourself, run the code (see compiling notes), create a new project and select a gadget (by clicking, doh!).
Change a value specific to that gadget (i.e. for a button, 'Text') and select a few other gadgets, it should crash with the typical "Unhandled Exception:appstub.linux signal handler 11" message.
NOTE: It may take a few tries, so if you have to do it more then once try selecting different gadgets and changing different gadget-specific properties.

COMPILING: libxml: http://www.blitzbasic.com/Community/posts.php?topic=78875
AND remember to move the frydwx.mod folder into your modules folder (also, you need pub.zipengine, koriolis.bufferedstream, and koriolis.zipstream )


Brucey(Posted 2008) [#2]
Okay... it's repeatable here on mine... having a look into it.


Brucey(Posted 2008) [#3]
Mac reports it better :

0   frydesigner.debug             	0x001c2b78 wxPGProperty::GetEditorClass() const + 36
1   frydesigner.debug             	0x001c8377 wxPropertyGrid::OnCustomEditorEvent(wxCommandEvent&) + 427
2   frydesigner.debug             	0x001c859a wxPropertyGrid::ProcessEvent(wxEvent&) + 54
3   frydesigner.debug             	0x00422d9c wxEvtHandler::ProcessEvent(wxEvent&) + 108
4   frydesigner.debug             	0x003aa74e wxScrollHelperEvtHandler::ProcessEvent(wxEvent&) + 46
5   frydesigner.debug             	0x00396c52 wxWindowBase::TryParent(wxEvent&) + 98
6   frydesigner.debug             	0x00422dac wxEvtHandler::ProcessEvent(wxEvent&) + 124
7   frydesigner.debug             	0x00396c52 wxWindowBase::TryParent(wxEvent&) + 98
8   frydesigner.debug             	0x00422dac wxEvtHandler::ProcessEvent(wxEvent&) + 124
9   frydesigner.debug             	0x0039b2e3 wxWindowBase::SendDestroyEvent() + 67
10  frydesigner.debug             	0x00306e48 wxWindow::~wxWindow() + 40
11  frydesigner.debug             	0x002f41b4 wxTextCtrl::~wxTextCtrl() + 148
12  frydesigner.debug             	0x001d078c wxPropertyGrid::DoSelectProperty(wxPGProperty*, unsigned int) + 106
13  frydesigner.debug             	0x001d3466 wxPropertyGridState::PrepareToAddItem(wxPGProperty*, wxPGProperty*) + 278
14  frydesigner.debug             	0x001d3700 wxPropertyGridState::DoInsert(wxPGProperty*, int, wxPGProperty*) + 60
15  frydesigner.debug             	0x001ca0c9 wxPropertyContainerMethods::AppendIn(wxPGPropArgCls const&, wxPGProperty*) + 67
16  frydesigner.debug             	0x001b14e6 bmx_wxpropertygrid_appendin + 46
...

Looks like it is happening in the same place on both... and kind of looks like a problem with wxPropgrid more than anything - but you never knows.


One thing on Mac, in fdcnv.bmx, in the OnKeyDown and OnKeyUp handlers, you event.Skip(), which the property editor doesn't like - ie. it's almost impossible to edit text. Commenting it out fixes that.

On an efficiency note, when the mouse is not over the canvas, does the canvas really need to be redrawing as often? Perhaps you could disable the timer when the mouse leaves? OnPaint() should still catch required refreshes.
Unless of course you are animating stuff in there? :-)


Brucey(Posted 2008) [#4]
How's about this.

Select a button or label, enter the editor for the text value (the property at the top), then, while the editor is live, click on the checkbox gadget (which doesn't have any extra props).
Looks like when you try to hide a live editor it breaks. (same on Linux and Mac)


Brucey(Posted 2008) [#5]
:-p
				Case wxEVT_LEAVE_WINDOW
					FryCanvas(event.parent).Tmr_ReDraw.Stop()
				
				Case wxEVT_ENTER_WINDOW
					FryCanvas(event.parent).Tmr_ReDraw.Start(10)



Brucey(Posted 2008) [#6]
Good news or the bad news? ;-)

Let's start with the good..

I found a way around that crash by adding a call to ClearSelection() in the SelectGadget() method of the GadgetPropGrid. That makes sure that if there is a current "editor" open, it closes it and posts the change.

However... the bad news...

An OnPropertyGridChanged event is raised, obviously, as there has been data changed, which in turn calls SetFieldValue on the gadget you think is being edited. But we've clicked on a new gadget now, which isn't the same one. The crash now occurs in the reflection module... I guess because you are telling it to change a TField on the wrong Object... (maybe not, but that's where it bombs).


So... what now?
I think you might need to change your logic a little.

When you click on a different gadget, *before* you start processing it, you might want to ClearSelection() on the grid - which will force the update of fields etc.
*then* carry on as you did before, hiding categories and whatnot.

When there isn't an active editor there are no issues.


Brucey(Posted 2008) [#7]
Hmm... I think I've fixed it...

In DrawScreen()...
					Case fry_EVENT_GADGETACTION
					  Local src:fry_TGadget = fry_TGadget(fry_EventSource())
	  
						mApp.Frame.m_gadprops.ClearSelection()    '<--- If an editor is active, this commits the change.

						DoSelection(src)
						
						mApp.Frame.m_gadlist.SetStringSelection(src.gName)


makes the crashing go away on Mac...


Brucey(Posted 2008) [#8]
So in summary, the above fix nullifies my Good news/bad news post altogether ;-)


plash(Posted 2008) [#9]
So... what now?
I think you might need to change your logic a little.
I wanted to get things *working*, and then do a redesign :P

On an efficiency note, when the mouse is not over the canvas, does the canvas really need to be redrawing as often? Perhaps you could disable the timer when the mouse leaves? OnPaint() should still catch required refreshes.
Good addition, I'll add your code.

So in summary, the above fix nullifies my Good news/bad news post altogether ;-)
Excellent!

P.S. sorry for the late response, vacation ;)

EDIT:
One thing on Mac, in fdcnv.bmx, in the OnKeyDown and OnKeyUp handlers, you event.Skip(), which the property editor doesn't like - ie. it's almost impossible to edit text. Commenting it out fixes that.
Hmm, never had that problem.. Commented it out anyways, hasn't hurt Linux yet.


plash(Posted 2008) [#10]
On an efficiency note, when the mouse is not over the canvas, does the canvas really need to be redrawing as often? Perhaps you could disable the timer when the mouse leaves? OnPaint() should still catch required refreshes.


Connect..
Connect(GetID(), wxEVT_LEAVE_WINDOW, OnMouseLeave)
Connect(GetID(), wxEVT_ENTER_WINDOW, OnMouseEnter)

'And the functions
Function OnMouseLeave(event:wxEvent)
			
	FryCanvas(event.parent).Tmr_ReDraw.Stop()
	DebugLog "MouseLeave?"
	
End Function

Function OnMouseEnter(event:wxEvent)
	
	FryCanvas(event.parent).Tmr_ReDraw.Start(10)
	DebugLog "MouseEnter!!"
	
End Function


OnMouseLeave() never gets called? (connected inside of FryCanvas)


Brucey(Posted 2008) [#11]
You need to be careful as you are already catching mouse events with:
ConnectAny(wxEVT_MOUSE_EVENTS, OnMouse)


Unless you've changed it.


plash(Posted 2008) [#12]
Oh, I was wondering why you used 'Case', OnMouse completely passed my mind.