wxFileDialog not showing up...sometimes

BlitzMax Forums/Brucey's Modules/wxFileDialog not showing up...sometimes

AlexO(Posted 2009) [#1]
Currently working on a map editor that uses wxGLCanvas to render the map.

When I click the 'save' menu item in my editor the save dialog sometimes doesn't even show up.
the method I have written is below

Method _GetMapSavePathFromDialog:String()
		Local saveFileDialog:wxFileDialog = wxFileDialog.CreateFileDialog(Self, "Save Level File",, "map", " Maps (*.gxm)|*.gxm", wxFD_SAVE | wxFD_OVERWRITE_PROMPT)
		Local result:Int = saveFileDialog.ShowModal()
		If result = wxID_OK Then
			Return saveFiledialog.GetPath()
		Else
			TLogger.LogError("error showing save dialog. error code: " + result + " wxID_CANCEL is " + wxID_CANCEL)
		End If
		Return ""
	End Method



At first i thought maybe the event was somehow being gobbled up in the file menu, but after further testing I've found that saveFileDialog.ShowModal() sometimes instantly returns wxID_CANCEL without ever showing up.

After running a few tests it would print the error message I have coded above:
"error showing save dialog. error code: 5101 wxID_CANCEL is 5101"

I'm on Windows XP SP3 and the last time I've had really 'weird' behavior like this is when I'd have a lot of heavy apps open (like multiple instances of blide, firefox, etc). From what I had gathered, I had hit some sort of 'limit' in terms of window handles, whereas on Vista the limit was much higher. I don't have access to a vista machine at the moment though to test this thoroughly.

I'm not sure where to even begin to debug this, any tips or ideas as to what might be going on would be greatly appreciated.


AlexO(Posted 2009) [#2]
Also, my editor's setup is a bit different so it might warrant an explanation to help in troubleshooting:
1. The game and editor executables are one in the same.
2. When the game starts it essentially calls Graphics(width,height)
3. When the user presses tilde a call to EndGraphics() happens and a wxApp is started (same process) with a wxGLCanvas
4. any graphical resources are reloaded and the user continues to edit the map
5. after which a ctrl+p closes the canvas and relaunches a default blitzmax graphics window on the fly (again same process).


Brucey(Posted 2009) [#3]
Try calling saveFileDialog.Free() before you Return/leave the method, to release the handle for the window.

In C++ you'd normally create the dialog on the stack, but with BlitzMax, you can't do this so easily, so instead we create a "new" instance of it on the heap instead. The caveat being that you then need to "free" the handle later.

It does however, allow you to re-use the same handle until you are done with it :
SuperStrict

Framework wx.wxApp
Import wx.wxFileDialog
Import BRL.StandardIO

New MyApp.run()

Type MyApp Extends wxApp

	Method OnInit:Int()

		Local saveFileDialog:wxFileDialog = wxFileDialog.CreateFileDialog(Null, "Save Level File",, "map", " Maps (*.gxm)|*.gxm", wxFD_SAVE | wxFD_OVERWRITE_PROMPT)
		
		Local result:Int = saveFileDialog.ShowModal()
		If result = wxID_OK Then
			Print "Path : " + saveFiledialog.GetPath()
		Else
			Print "error showing save dialog. error code: " + result + " wxID_CANCEL is " + wxID_CANCEL
		End If
		
		result = saveFileDialog.ShowModal()
		If result = wxID_OK Then
			Print "Path : " + saveFiledialog.GetPath()
		Else
			Print "error showing save dialog. error code: " + result + " wxID_CANCEL is " + wxID_CANCEL
		End If
		
		' release
		saveFileDialog.Free()
		
		Return False
	
	End Method

End Type


I was sure I'd mentioned the Free() requirement in the documentation, but it seems not - which doesn't help matters very much I think...


AlexO(Posted 2009) [#4]
I had noticed in the documentation the free() was only called for the messagediaglog examples and not the filedialog examples. I wasn't sure why one did and the other did not. I will give this a go with calls to free() again and see if it works, thanks.

Ps. I did try a free() on the filedialog prior to starting this thread and got a crash from it but I'm not 100% sure if it was my fault or not. I'll verify tonight and reply.


AlexO(Posted 2009) [#5]
I've added the free() calls to the relevant dialogs and it seems to be working now. Thanks :)


Schnuff(Posted 2010) [#6]
Hi, i have a simmilar problem...

In my case, the filedialog dosn't show up at all (even if i recompile and re-run the programm)
at the first try it all is working correctly (the first time, i ran the programm on my Win7 notebook), i can open this dialog and so on...
But if i try it later, fileDialog.ShowModal() everytime returns a "CANCEL".

So I've tried fileDialog.Free() but this will only let the App crash whitout any Debuginfo... (the Windows "The Application dosn't react" dialog shows up)

[Edit]Hm, strange, your example (the mediaplayer) dosn't have this "bug"[/Edit]

Type TFrameMain Extends wxFrame
	
	'Field fileDialogOpen:wxFileDialog
	'Field fileDialogSave:wxFileDialog
	
	Method OnInit()
		' I've tried to create two dialoges "global" so i musn't create it everytime from "ground up" but those dialoges wouldn't show up too.
		
		'Self.fileDialogOpen = wxFileDialog.CreateFileDialog(Self, lang.FileDialog_Save_Title,,, "BlitzMax (*.bmx)|*.bmx", wxFD_OPEN | wxFD_FILE_MUST_EXIST)
		'Self.fileDialogSave = wxFileDialog.CreateFileDialog(Self, lang.FileDialog_Save_Title,,, "BlitzMax (*.bmx)|*.bmx", wxFD_SAVE | wxFD_OVERWRITE_PROMPT)
	End Method
	
	Method showLoadDialog()
		Local fileDialogOpen:wxFileDialog = New wxFileDialog.Create(Self, lang.FileDialog_Save_Title,,, "BlitzMax (*.bmx)|*.bmx", wxFD_OPEN | wxFD_FILE_MUST_EXIST)
		Local tmp:Int = fileDialogOpen.ShowModal()
		If tmp = wxID_OK Then
			Print"load Accepted"
		Else
			Print"load Canceled (Code: "+tmp+")"
		EndIf
		fileDialogOpen.Free() ' <-- Here the Application Crashes...
	End Method

End Type


PS: It dosn't help to write a "Null" as the first parameter of wxFileDialog.Create...

OS: Win7 (32bit), Ubuntu (the newest)


DavidDC(Posted 2010) [#7]
Are you able to use wxFileSelector instead?


Schnuff(Posted 2010) [#8]
Yes, the FileSelector does it :D

if i use the fileselector everything is working like it should
thanks for your help DavidDC :D