Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

*mix.Chunk.setVolume() fails on Windows 7 #98

Closed
ghost opened this issue Mar 1, 2015 · 3 comments
Closed

*mix.Chunk.setVolume() fails on Windows 7 #98

ghost opened this issue Mar 1, 2015 · 3 comments

Comments

@ghost
Copy link

ghost commented Mar 1, 2015

So I finally got everything compiling and running under Windows (Win 7 32 bit using MSYS and MinGW). However, one function call causes a cgo exception with the following output:

Exception 0xc0000005 0x0 0xc 0x6788777b
PC=0x6788777b
signal arrived during cgo execution

github.com/veandco/go-sdl2/sdl_mixer._Cfunc_Mix_VolumeChunk(0x0, 0x63, 0x0)
    C:/dev/golang/src/github.com/veandco/go-sdl2/sdl_mixer/:443 +0x3f
github.com/veandco/go-sdl2/sdl_mixer.(*Chunk).SetVolume(0x0, 0x63, 0x115cff24)
    C:/dev/golang/src/github.com/veandco/go-sdl2/sdl_mixer/sdl_mixer.go:270 +0x30
main.initAudio()
    C:/dev/01_hello_SDL/revenge-of-the-gopher/src/audio.go:27 +0x162
main.main()
    C:/dev/01_hello_SDL/revenge-of-the-gopher/src/main.go:35 +0xf7

goroutine 17 [syscall, locked to thread]:
runtime.goexit()
    c:/go/src/runtime/asm_386.s:2287 +0x1
eax     0x0
ebx     0x0
ecx     0x5ab440
edx     0x63
edi     0x115d0000
esi     0x5a36c0
ebp     0x5a38e0
esp     0x12fe98
eip     0x6788777b
eflags  0x210206
cs      0x1b
fs      0x3b
gs      0x0
exit status 2

The offending function looks like this:

var gameAudio audio

type audio struct {
explode1, laser1, playerDeath *mix.Chunk
enemyHit, powerUp1Active      *mix.Chunk
intro, bgmusic                *mix.Music
}

func initAudio() {
mix.OpenAudio(22050, mix.DEFAULT_FORMAT, 2, 4096)

gameAudio = audio{
    explode1:       mix.LoadWAV("assets/SFX_Explosion_01.ogg"),
    laser1:         mix.LoadWAV("assets/Laser1.ogg"),
    playerDeath:    mix.LoadWAV("assets/player_death.ogg"),
    enemyHit:       mix.LoadWAV("assets/enemy_hit.ogg"),
    powerUp1Active: mix.LoadWAV("assets/powerup1_active.ogg"),

    bgmusic: mix.LoadMUS("assets/bgmusic1.ogg"),
    intro:   mix.LoadMUS("assets/bgmusic6.ogg"),
}

gameAudio.enemyHit.SetVolume(100)
gameAudio.laser1.SetVolume(20)
gameAudio.playerDeath.SetVolume(75)
}

Line 27 in audio.go refers to the line containing "gameAudio.enemyHit.SetVolume(100)".

The entire project is available here: https://github.com/Decker108/revenge-of-the-gopher/tree/060094c0d2140bf9dacd10a4485c97813b49134f

@akovaski
Copy link
Contributor

akovaski commented Mar 3, 2015

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)

@ghost
Copy link
Author

ghost commented Mar 3, 2015

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".

@ghost ghost closed this as completed Mar 3, 2015
@krux02
Copy link
Contributor

krux02 commented Mar 27, 2015

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.

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants