~ubuntu-branches/ubuntu/trusty/manaplus/trusty

« back to all changes in this revision

Viewing changes to src/resources/sdlmusic.cpp

  • Committer: Package Import Robot
  • Author(s): Patrick Matthäi
  • Date: 2013-10-07 10:26:14 UTC
  • mfrom: (1.1.11)
  • Revision ID: package-import@ubuntu.com-20131007102614-tg2zjdz8vmtl6n7i
Tags: 1.3.9.29-1
New upstream release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
26
26
 
27
27
#include "debug.h"
28
28
 
29
 
SDLMusic::SDLMusic(Mix_Music *const music) :
 
29
SDLMusic::SDLMusic(Mix_Music *const music, SDL_RWops *const rw) :
30
30
    Resource(),
31
 
    mMusic(music)
 
31
    mMusic(music),
 
32
    mRw(rw)
32
33
{
33
34
}
34
35
 
35
36
SDLMusic::~SDLMusic()
36
37
{
37
38
    Mix_FreeMusic(mMusic);
 
39
#ifndef USE_SDL2
 
40
    if (mRw)
 
41
    {
 
42
        SDL_RWclose(mRw);
 
43
        mRw = nullptr;
 
44
    }
 
45
#endif
38
46
}
39
47
 
40
48
Resource *SDLMusic::load(SDL_RWops *const rw)
41
49
{
42
50
#ifdef USE_SDL2
43
51
    if (Mix_Music *const music = Mix_LoadMUSType_RW(rw, MUS_OGG, 1))
 
52
    {
 
53
        return new SDLMusic(music, nullptr);
 
54
    }
44
55
#else
45
 
    // +++ here probably mem leak
46
56
    // Mix_LoadMUSType_RW was added without version changed in SDL1.2 :(
47
57
    if (Mix_Music *const music = Mix_LoadMUS_RW(rw))
 
58
    {
 
59
        return new SDLMusic(music, rw);
 
60
    }
48
61
#endif
49
 
    {
50
 
        return new SDLMusic(music);
51
 
    }
52
62
    else
53
63
    {
54
64
        logger->log("Error, failed to load music: %s", Mix_GetError());