Coder Social home page Coder Social logo

Unknown event type: 8192 about go-sdl2 HOT 13 CLOSED

veandco avatar veandco commented on July 18, 2024
Unknown event type: 8192

from go-sdl2.

Comments (13)

aqiank avatar aqiank commented on July 18, 2024

Could you post the code of your program? I tried reproducing it but it didn't panic.

from go-sdl2.

Forsevin avatar Forsevin commented on July 18, 2024

Relevant code:
https://gist.github.com/Forsevin/24f1aaf10001efab9597

It's not exactly the same project but input is handled mostly in the same way as here
https://github.com/Forsevin/Not3D/blob/master/n3/input.go

from go-sdl2.

aqiank avatar aqiank commented on July 18, 2024

Could you post minimal version of your main package code that panics?

from go-sdl2.

Forsevin avatar Forsevin commented on July 18, 2024

After some tracking the cause most likely have something to do with textures.

Calling the renderer.Clear() method with or without any textures being rendered will cause the panic, rendering a texture without clearing the renderer will also cause a panic. But by not rendering anything and removing renderer.Clear() I was able to resize the window without any panics.

Like I said, I most probably just forgot or done something wrong.

Render code:
https://gist.github.com/Forsevin/040e3a9b3c8bc08b7332

from go-sdl2.

aqiank avatar aqiank commented on July 18, 2024

Is it possible for you to leave out all your other code and narrow down to just the go-sdl2 code (along with the main function)? That would make it easier to find out about the issue. At the moment, I can't do anything to help you as I can only speculate about your code.

For example this code works fine, at least for me. Maybe you can use it as a starting point? (don't forget to include an image called "test.bmp" though):

package main

import (
    "github.com/veandco/go-sdl2/sdl"
    "fmt"
    "os"
)

var winTitle string = "Go-SDL2 Texture"
var winWidth, winHeight int = 800, 600
var imageName string = "test.bmp"

func main() {
    var window *sdl.Window
    var renderer *sdl.Renderer
    var image *sdl.Surface
    var texture *sdl.Texture
    var src, dst sdl.Rect

    window = sdl.CreateWindow(winTitle, sdl.WINDOWPOS_UNDEFINED, sdl.WINDOWPOS_UNDEFINED,
            winWidth, winHeight, sdl.WINDOW_SHOWN | sdl.WINDOW_RESIZABLE)
    if window == nil {
        fmt.Fprintf(os.Stderr, "Failed to create window: %s\n", sdl.GetError());
        os.Exit(1);
    }

    renderer = sdl.CreateRenderer(window, -1, sdl.RENDERER_ACCELERATED)
    if renderer == nil {
        fmt.Fprintf(os.Stderr, "Failed to create renderer: %s\n", sdl.GetError());
        os.Exit(2);
    }

    image = sdl.LoadBMP(imageName)
    if image == nil {
        fmt.Fprintf(os.Stderr, "Failed to load BMP: %s\n", sdl.GetError())
        os.Exit(3);
    }

    texture = renderer.CreateTextureFromSurface(image)
    if texture == nil {
        fmt.Fprintf(os.Stderr, "Failed to create texture: %s\n", sdl.GetError());
        os.Exit(4);
    }

    src = sdl.Rect { 0, 0, 512, 512 }
    dst = sdl.Rect { 100, 50, 512, 512 }

    running := true
    for running {
        for event := sdl.PollEvent(); event != nil; event = sdl.PollEvent() {
            switch event.(type) {
            case *sdl.QuitEvent:
                running = false
            }
        }
        renderer.Clear()
        renderer.Copy(texture, &src, &dst)
        renderer.Present()
    }

    image.Free()
    texture.Destroy()
    renderer.Destroy()
    window.Destroy()
}

from go-sdl2.

Forsevin avatar Forsevin commented on July 18, 2024

I temporarily avoid the problem by not panicking when a unknown event appears, so far it hasn't given me any problems.

This is my SDL2 code: https://gist.github.com/Forsevin/a614f45a13889d68be48

from go-sdl2.

gonutz avatar gonutz commented on July 18, 2024

I am experiencing the same problem and have created the minimal example to reproduce it. When running the following code and then resizing the window it will panic with the above mentioned message:

package main

import "github.com/veandco/go-sdl2/sdl"

var window *sdl.Window
var renderer *sdl.Renderer

func main() {
    window, renderer = sdl.CreateWindowAndRenderer(640, 320, sdl.WINDOW_RESIZABLE)
    defer window.Destroy()
    defer renderer.Destroy()

    running := true
    for running {
        for event := sdl.PollEvent(); event != nil; event = sdl.PollEvent() {
            switch event.(type) {
            case *sdl.QuitEvent:
                running = false
            }
        }
        draw()
    }

    sdl.Quit()
}

func draw() {
    renderer.FillRect(nil)
}

Note that this will only crash for me under Windows, Linux does not have a problem with it. Also I am using 64 bit versions of these operating systems.

Please fix the problem because I have to disable resizing until it is fixed. Thank you very much in advance!

from go-sdl2.

krux02 avatar krux02 commented on July 18, 2024

according to SDL_events.h we have SDL_RENDER_TARGETS_RESET = 0x2000. And 0x2000 in hex is the same as 8192 in decimal. So maybe this event is not implemented.

from go-sdl2.

gonutz avatar gonutz commented on July 18, 2024

Are you working on the problem right now or is anyone else taking care of it?

from go-sdl2.

aqiank avatar aqiank commented on July 18, 2024

Sorry, will look into it soon. Just a little busy at the moment.

from go-sdl2.

gonutz avatar gonutz commented on July 18, 2024

Great, thanks for taking the time, I appreciate it.

from go-sdl2.

aqiank avatar aqiank commented on July 18, 2024

Hi, the latest commit should prevent it from crashing. I added a default case in goEvent() that returns CommonEvent.

from go-sdl2.

aqiank avatar aqiank commented on July 18, 2024

nlordell's patch should now let you receive RenderEvent when resizing windows.

from go-sdl2.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.