Comments (3)
Your LoadWAV calls are probably failing (at least it is for your project on my machine). Check that gameAudio.enemyHit et al. are not nil.
I suspect that your sdl_mixer installation is not built with ogg support.
That being said, perhaps some changes should be made to the sdl_mixer library:
-
This is an unpleasant way to crash... a nil check in the Chunk methods might be a worthwhile investment
- This version of SetVolume() would result in a nil-pointer panic instead of the somewhat cryptic panic it currently does
func (chunk Chunk) SetVolume(volume int) int { _chunk := (*C.Mix_Chunk)(unsafe.Pointer(&chunk)) _volume := (C.int)(volume) return (int)(C.Mix_VolumeChunk(_chunk, _volume)) }
-
It's hard to tell what's wrong with loading the file (can it not find the file? is the filetype not supported?) without Mix_GetError
- What LoadWav() with error checking could look like
func LoadWAV(file string) (c *Chunk, err error) { _file := C.CString(file) defer C.free(unsafe.Pointer(_file)) _rb := C.CString("rb") defer C.free(unsafe.Pointer(_rb)) rwFile := C.SDL_RWFromFile(_file, _rb) if rwFile == nil { return nil, errors.New(C.GoString(C.Mix_GetError())) } c = (*Chunk)(unsafe.Pointer(C.Mix_LoadWAV_RW(rwFile, 1))) if c == nil { return nil, errors.New(C.GoString(C.Mix_GetError())) } return c, nil }
Please try using this version of LoadWAV to see if your files are not being loaded. (the "errors" package must also be imported in sdl_mixer.go)
from go-sdl2.
Sorry, I screwed up. I built the game with go run outside the game folder... and then it couldn't find the asset files and threw this exception.
More idiomatic error handling for sdl_mixer would be a nice thing though :)
I implemented your loadWav function and got this output:
2015/03/03 19:38:40 Couldn't open assets/SFX_Explosion_01.ogg
exit status 1
Which of course make sense since the application is run from outside the intended folder.
I'm closing this issue as "error exists between keyboard and chair".
from go-sdl2.
actually I am writing at the moment more ideomatic error for the mixer. But it's a compatibility changing. Especially SetVolume is now called like the original function just Volume, because it's also the getter.
from go-sdl2.
Related Issues (20)
- No way to get enter key event when using sdl.WaitEvent() HOT 1
- 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
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.