Comments (13)
Could you post the code of your program? I tried reproducing it but it didn't panic.
from go-sdl2.
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.
Could you post minimal version of your main package code that panics?
from go-sdl2.
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.
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.
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.
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.
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.
Are you working on the problem right now or is anyone else taking care of it?
from go-sdl2.
Sorry, will look into it soon. Just a little busy at the moment.
from go-sdl2.
Great, thanks for taking the time, I appreciate it.
from go-sdl2.
Hi, the latest commit should prevent it from crashing. I added a default case in goEvent() that returns CommonEvent.
from go-sdl2.
nlordell's patch should now let you receive RenderEvent when resizing windows.
from go-sdl2.
Related Issues (20)
- WASI Support
- Not compatible with Go 1.21.0 HOT 7
- SDL/SDL.h: No such file or directory HOT 2
- How to ship release version HOT 4
- Surface panics on color conversions due to nonidiomatic color models HOT 4
- Windows release crashing likely because C.CString deallocated with C.SDL_free HOT 3
- Getting an errror when compiling to wasm HOT 2
- impossible type switch case: sdl.QuitEvent HOT 4
- Cannot find -lsdl2 HOT 10
- SDL_AudioStreamAvailable not correctly wrapped HOT 2
- Missing functions in gamecontroller.go HOT 6
- Readme Example Fix typo HOT 2
- Running readme example yields 30% CPU usage HOT 13
- Fails to link with musl libc HOT 1
- feature req: img.LoadSizedSVG HOT 2
- SdlSetTextureScaleMode HOT 7
- Window Doesn't Show HOT 4
- How to SDL on 64bit Windows Instructions Unclear
- (suggestion) Convert sdl.Rect Fields from int32 to int HOT 3
- pkg-config issue with sdl2_gfx 0.4.35->0.4.39 HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from go-sdl2.