jacius / ruby-sdl-ffi

Ruby-FFI binding to SDL multimedia libraries. (Still in alpha)
http://jacius.github.com/ruby-sdl-ffi/
16 stars 6 forks source link

Crashes when using SDL.OpenAudio directly #1

Closed rhp closed 13 years ago

rhp commented 15 years ago

Hi,

I am trying to set-up a program in which I use SDL to play some sound from a pre-loaded buffer. Using the callback method for OpenAudio gives me some trouble: it crashes after running through a few loops of the callback method.

See this example:

#! /usr/bin/ruby -w

require 'rubygems'
require 'ruby-sdl-ffi'

SDL.Init(SDL::INIT_AUDIO)

spec = 
    SDL::AudioSpec.new(
        :freq => 22100,
        :format => SDL::AUDIO_S16,
        :channels => 2,
    :silence => 0,
        :samples => 512,
    :padding => 0,
    :size => 0,
        :userdata => nil,
        :callback => Proc.new { |unused, stream, len|
            p stream
            p len
        }
    )

raise "Could not open SDL audio" if SDL.OpenAudio(spec, nil) < 0

SDL.PauseAudio(0)

loop do
    SDL.PollEvent do |event|
        case event
            when SDL::QuitEvent
            exit(0)
            else
                # Do nothing
        end
    end
end
rhp commented 15 years ago

Auch... that didn't go entirely right... But I think you get the point...

jacius commented 14 years ago

Hi. This library is still very young, so things are expected not to work. Thanks for the report though, I'll be sure to fix it in the future.

As a workaround until this is fixed, I would suggest using SDL::Mixer::OpenAudio instead, if you don't need all the advanced AudioSpec stuff.

jacius commented 13 years ago

"Moved" this issue to rubygame/ruby-sdl-ffi#1.