manyminds / gosfml

gosfml2 are go bindings for SFML 2.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Scrolling Mouse Wheel crashes window

Dacode45 opened this issue · comments

Whenever I scroll with my mouse in the window, the window crashes.
The crash is in handleEvent in event.go. It's especially weird considering that scrolling the mouse wheel actually causes a value of 8 (EventTypeMouseButtonReleased) to be sent. I put a fallthrough for case 8 right above that for EventTypeMouseButtonReleased, and no more crashes.

commented

Could you provide example code?

I get this crash as well on Linux here's the log

panic: Unknown event

goroutine 1 [running, locked to thread]:
github.com/manyminds/gosfml.handleEvent(0xc820086d20, 0x0, 0x0)
        /home/varomix/gowork/src/github.com/manyminds/gosfml/event.go:311 +0x1e3
github.com/manyminds/gosfml.(*RenderWindow).PollEvent(0xc820092000, 0x0, 0x0)
        /home/varomix/gowork/src/github.com/manyminds/gosfml/renderWindow.go:143 +0xae
main.main()
        /home/varomix/gowork/src/github.com/manyminds/gosfml/samples/sfmlShaders/main.go:68 +0x8dc

goroutine 17 [syscall, locked to thread]:
runtime.goexit()
        /usr/local/go/src/runtime/asm_amd64.s:1721 +0x1
exit status 2
commented

The samples were still using the old import path, could you try again with the latest master?

I modified the path in the example, so is actually using the latest

commented

which version of cfsml are you using?

Sorry for the late reply. i got this to work by changing handleEvent in event.go to

func handleEvent(cEvent *C.sfEvent) (ev Event) {
    switch EventType(C.getEventType(cEvent)) {
    case EventTypeResized:

        ev = newSizeEventFromC(C.getSizeEvent(cEvent))
    case EventTypeClosed:
        ev = EventClosed{}
    case EventTypeLostFocus:
        ev = EventLostFocus{}
    case EventTypeGainedFocus:
        ev = EventGainedFocus{}
    case EventTypeTextEntered:
        ev = newTextEventFromC(C.getTextEvent(cEvent))
    case EventTypeKeyReleased:
        ev = (EventKeyReleased)(newKeyEventFromC(C.getKeyEvent(cEvent)))
    case EventTypeKeyPressed:
        ev = (EventKeyPressed)(newKeyEventFromC(C.getKeyEvent(cEvent)))
    case EventTypeMouseWheelMoved:
        ev = newMouseWheelEventFromC(C.getMouseWheelEvent(cEvent))
    case 8:
        fallthrough
    case EventTypeMouseButtonReleased:
        ev = (EventMouseButtonReleased)(newMouseButtonEventFromC(C.getMouseButtonEvent(cEvent)))
    case EventTypeMouseButtonPressed:
        ev = (EventMouseButtonPressed)(newMouseButtonEventFromC(C.getMouseButtonEvent(cEvent)))
    case EventTypeMouseMoved:
        ev = newMouseMoveEventFromC(C.getMouseMoveEvent(cEvent))
    case EventTypeMouseLeft:
        ev = EventMouseLeft{}
    case EventTypeMouseEntered:
        ev = EventMouseEntered{}
    case EventTypeJoystickButtonReleased:
        ev = (EventJoystickButtonReleased)(newJoystickButtonEventFromC(C.getJoystickButtonEvent(cEvent)))
    case EventTypeJoystickButtonPressed:
        ev = (EventJoystickButtonPressed)(newJoystickButtonEventFromC(C.getJoystickButtonEvent(cEvent)))
    case EventTypeJoystickMoved:
        ev = newJoystickMoveEventFromC(C.getJoystickMoveEvent(cEvent))
    case EventTypeJoystickDisconnected:
        ev = (EventJoystickDisconnected)(newJoystickConnectEventFromC(C.getJoystickConnectEvent(cEvent)))
    case EventTypeJoystickConnected:
        ev = (EventJoystickConnected)(newJoystickConnectEventFromC(C.getJoystickConnectEvent(cEvent)))
    default:
        panic("Unknown event")
    }
    return
}

I just inserted a case 8

commented

Thx for the hint. Could you do me a favor and test #2 for me? It also won't panic your application anymore.

I currently got no linux system :-) Thx!

I tested in Linux and the fix_window_scroll_events branch on linux and is working great

thanks

commented

thanks for your support :-)

I tried installing this from scratch in my other linux box and I'm getting this error

go get -u github.com/manyminds/gosfml
# github.com/manyminds/gosfml
could not determine kind of name for C.sfEvtMouseWheelScrolled

also when I try to run the examples

commented

ok I will fix this properly tomorrow. Some tests won't hurt. :-) sry for the trouble.

commented

Could you check the cfsml versions on both machines?

the one that works has 2.3.2
the other one has 2.1.2

I'll try to update and see if that fixes that

commented

yeah the current repository should only works for 2.3.* - if you need to use an older version you might try the original repository instead.