GithubHelp home page GithubHelp logo

Comments (3)

akovaski avatar akovaski commented on July 16, 2024

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.

 avatar commented on July 16, 2024

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.

krux02 avatar krux02 commented on July 16, 2024

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)

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.