Reordered each part of the Windows uitask so that it does things in the same order and with the same goroutine setup as the other platforms; this gets rid of a few channels. Also panics on more errors (gets rid of a few more channels) and removed some stray TODOs.

This commit is contained in:
Pietro Gagliardi 2014-04-01 15:14:57 -04:00
parent acc0f72379
commit b2f0fe1956
2 changed files with 19 additions and 37 deletions

View File

@ -2,8 +2,6 @@ so I don't forget:
- Window.SizeToFit() or WIndow.OptimalSize() (use: `Window.SetOptimalSize())`) for sizing a window to the control's interest - Window.SizeToFit() or WIndow.OptimalSize() (use: `Window.SetOptimalSize())`) for sizing a window to the control's interest
- Control.Show()/Control.Hide() - Control.Show()/Control.Hide()
- Groupbox - Groupbox
- see if we really need to track errors on a lot of places that report errors
- it appears GTK+ and Cocoa both either don't provide a convenient way to grab errors or you're not supposed to; I assume you're supposed to just assume everything works... but on Windows we check errors for functions that return errors, and there's no guarantee that only certian errors will be returned...
- character-limited entry fields, numeric entry fields, multiline entry fields - character-limited entry fields, numeric entry fields, multiline entry fields
- possible rename of LineEdit? - possible rename of LineEdit?
- especially for password fields - NewPasswordEntry()? - especially for password fields - NewPasswordEntry()?
@ -65,7 +63,6 @@ super ultra important things:
- the windows build appears to be unstable: - the windows build appears to be unstable:
- 64-bit crashes in malloc in wine with heap corruption warnings aplenty during DLL loading; in windows 7 it works fine - 64-bit crashes in malloc in wine with heap corruption warnings aplenty during DLL loading; in windows 7 it works fine
- 32-bit: it works, but if I save the class name converted to UTF-16 beforehand, wine indicates that the class name is replaced with the window title, so something there is wrong... - 32-bit: it works, but if I save the class name converted to UTF-16 beforehand, wine indicates that the class name is replaced with the window title, so something there is wrong...
- handle in-library panics (internal errors) by reporting them to the user
- david wendt is telling me he's getting frequent crashes on his end with the GTK+ amd64 build... - david wendt is telling me he's getting frequent crashes on his end with the GTK+ amd64 build...
TODO re-evaluate; I think I fixed them all ages ago now TODO re-evaluate; I think I fixed them all ages ago now
- occasionally I get - occasionally I get

View File

@ -35,6 +35,7 @@ const (
) )
var ( var (
_getCurrentThreadID = kernel32.NewProc("GetCurrentThreadId")
_postThreadMessage = user32.NewProc("PostThreadMessageW") _postThreadMessage = user32.NewProc("PostThreadMessageW")
) )
@ -47,10 +48,20 @@ func ui(main func()) error {
return err return err
} }
threadIDReq := make(chan uintptr) threadID, _, _ := _getCurrentThreadID.Call()
msglooperrs := make(chan error)
go msgloop(threadIDReq, msglooperrs) go func() {
threadID := <-threadIDReq for m := range uitask {
r1, _, err := _postThreadMessage.Call(
threadID,
msgRequested,
uintptr(0),
uintptr(unsafe.Pointer(m)))
if r1 == 0 { // failure
panic("error sending message to message loop to call function: " + err.Error()) // TODO
}
}
}()
go func() { go func() {
main() main()
@ -60,30 +71,11 @@ func ui(main func()) error {
uintptr(0), uintptr(0),
uintptr(0)) uintptr(0))
if r1 == 0 { // failure if r1 == 0 { // failure
panic("error sending quit message to message loop: " + err.Error()) // TODO panic("error sending quit message to message loop: " + err.Error())
} }
}() }()
quit := false msgloop()
for !quit {
select {
case m := <-uitask:
r1, _, err := _postThreadMessage.Call(
threadID,
msgRequested,
uintptr(0),
uintptr(unsafe.Pointer(m)))
if r1 == 0 { // failure
panic("error sending message to message loop to call function: " + err.Error()) // TODO
}
case err := <-msglooperrs:
if err == nil { // WM_QUIT; no error
quit = true
} else {
panic("unexpected return from message loop: " + err.Error()) // TODO
}
}
}
doWindowsQuitStuff() doWindowsQuitStuff()
return nil return nil
@ -92,7 +84,6 @@ func ui(main func()) error {
var ( var (
_dispatchMessage = user32.NewProc("DispatchMessageW") _dispatchMessage = user32.NewProc("DispatchMessageW")
_getMessage = user32.NewProc("GetMessageW") _getMessage = user32.NewProc("GetMessageW")
_getCurrentThreadID = kernel32.NewProc("GetCurrentThreadId")
_postQuitMessage = user32.NewProc("PostQuitMessage") _postQuitMessage = user32.NewProc("PostQuitMessage")
_sendMessage = user32.NewProc("SendMessageW") _sendMessage = user32.NewProc("SendMessageW")
_translateMessage = user32.NewProc("TranslateMessage") _translateMessage = user32.NewProc("TranslateMessage")
@ -100,9 +91,7 @@ var (
var getMessageFail = -1 // because Go doesn't let me var getMessageFail = -1 // because Go doesn't let me
func msgloop(threadID chan uintptr, errors chan error) { func msgloop() {
runtime.LockOSThread()
var msg struct { var msg struct {
Hwnd _HWND Hwnd _HWND
Message uint32 Message uint32
@ -112,8 +101,6 @@ func msgloop(threadID chan uintptr, errors chan error) {
Pt _POINT Pt _POINT
} }
r1, _, _ := _getCurrentThreadID.Call()
threadID <- r1
for { for {
r1, _, err := _getMessage.Call( r1, _, err := _getMessage.Call(
uintptr(unsafe.Pointer(&msg)), uintptr(unsafe.Pointer(&msg)),
@ -121,11 +108,9 @@ func msgloop(threadID chan uintptr, errors chan error) {
uintptr(0), uintptr(0),
uintptr(0)) uintptr(0))
if r1 == uintptr(getMessageFail) { // error if r1 == uintptr(getMessageFail) { // error
errors <- err panic("error getting message in message loop: " + err.Error())
return
} }
if r1 == 0 { // WM_QUIT message if r1 == 0 { // WM_QUIT message
errors <- nil
return return
} }
if msg.Message == msgRequested { if msg.Message == msgRequested {