SDL_mixer exception at Mix_PlayMusic

Member
Posts: 20
Joined: 2006.06
Post: #1
I have never used SDL_mixer and I am a novice when it comes to real debugging with xcode. Anyway, I was attempting to get mixer working and have immediately run into an issue. Basically, when I attempt to call Mix_PlayMusic it explodes.

My pertinent code (based of the gpwiki code:
Code:
#include <cstdio>
#include <cstdlib>
#include <string>

#include "SDL.h"
#include "SDL_image.h"
#include "SDL_mixer.h"

#define COLORKEY 255, 255, 255

const std::string asset_path = "assets/";
const std::string music_filename = asset_path + "some_song_on_my_disk.ogg";

int main( int argc, char *argv[ ]) {
    Uint32 initflags = SDL_INIT_VIDEO;
    SDL_Surface *screen;
    Uint8 video_bpp = 0;
    Uint32 videoflags = SDL_SWSURFACE | SDL_DOUBLEBUF;// | SDL_FULLSCREEN | SDL_NOFRAME;
    int done;
  SDL_Event event;

    /* Initialize the SDL library */
    if ( SDL_Init( initflags ) < 0 ) {
        fprintf(stderr, "Couldn't initialize SDL: %s\n",
            SDL_GetError( ));
        exit( 1 );
    }

  
    /* Set 640x480 video mode */
    screen = SDL_SetVideoMode( 640, 480, video_bpp, videoflags );
  if ( !screen ) {
        fprintf( stderr, "Couldn't set 640x480x%d video mode: %s\n",
             video_bpp, SDL_GetError( ));
        SDL_Quit( );
        exit( 2 );
    }

  printf( "Loading music\n" );
  Mix_Music *music = NULL;
  music = Mix_LoadMUS( music_filename.c_str( ));
  if( !music ) {
      printf( "Unable to load Ogg file: %s\n", Mix_GetError( ));
    SDL_Quit( );
      exit( 5 );
  }
  printf( "Music loaded\n" );
  
  if(Mix_PlayMusic(music, 0) == -1) {
      printf("Unable to play Ogg file: %s\n", Mix_GetError());
      SDL_Quit( );
    exit( 6 );
  }
  
  
  done = 0;
    while ( !done ) {
        /* Check for events */
        while ( SDL_PollEvent( &event )) {
            switch ( event.type ) {
                case SDL_MOUSEMOTION:
                    break;
                case SDL_MOUSEBUTTONDOWN:
                    break;
        /* Any keypress quits the app... */
                case SDL_KEYDOWN:
                case SDL_QUIT:
                    done = 1;
                    break;
                default:
                    break;
            }
        }
    

    SDL_Flip(screen); //Refresh the screen
    SDL_Delay( 50 ); //Wait a bit :)
    }
    

  Mix_HaltMusic();
  Mix_FreeMusic(music);
  Mix_CloseAudio();
  
    /* Clean up the SDL library */
    SDL_Quit( );
    return( 0 );
}

The stack trace that xcode gives me jumps into Mix_PlayMusic and below that Mix_FadeInMusicPos (some assembly dump). Any ideas? Anyone know how to get xcode to tell you what exactly triggered the exception/halt of program?
Quote this message in a reply
Moderator
Posts: 704
Joined: 2002.04
Post: #2
From a quick look at your code, you haven't called Mix_OpenAudio() anywhere prior to the loading/playing of the music...

Edit: also, I believe you need to pass the flags ( SDL_INIT_VIDEO | SDL_INIT_AUDIO ) to SDL_Init()...

Mark Bishop
--
Student and freelance OS X & iOS developer
Quote this message in a reply
Member
Posts: 20
Joined: 2006.06
Post: #3
Oh wow. I was just following http://gpwiki.org/index.php/C:Using_SDL_...music_file without putting much thought into it. Thanks a lot.
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  SDl_mixer and image bronxbomber92 3 3,608 Dec 15, 2006 12:27 PM
Last Post: bronxbomber92
  Installing SDL_image &amp; SDL_mixer bronxbomber92 8 5,913 Oct 14, 2006 09:39 PM
Last Post: szymczyk
  Using SDL_mixer to play ogg sound (not music) effects kordova 3 6,600 Sep 1, 2006 12:29 PM
Last Post: kordova
  SDL/SDL_mixer problems with Xcode poffy 1 3,684 Mar 7, 2006 02:45 AM
Last Post: OneSadCookie
  SDL_mixer crashing on loop - why? sealfin 8 5,975 Jan 26, 2005 09:25 PM
Last Post: aaronsullivan