I'm using the derelict fmod bindings to handle sounds in my application and I'm running into a weird bug... If I put calls to fmod in a function inside a class, upon calling those functions the instance of that class will be null, or otherwise changed. I obviously get an access violation if I try to do anything with that instance of the class while it's null.

class Audio {
    FMOD_SOUND* audio;
    FMOD_SYSTEM* fmod;

    this(){
        //initialization code
    }
    void load(string path){
FMOD_System_CreateSound(fmod, path.toStringz, 0, null, &audio);
    }
}

Audio a;

void main(){
    writeln(&a); // 281478
    a = new Audio();
    writeln(&a); // 281478
    a.load("audio.ogg");
    writeln(&a); // null
    ... //some time later
    writeln(&a); // 281478
}

It happens even when I rearrange example code to be inside a class
https://github.com/Extrawurst/DerelictFmod/blob/v4.1.0/source/app.d

The calls work and don't return an error code. I can play music as long as I load and play within the same function call. Just the surrounding class reference gets messed up? And if I check later in the program the instance will return to its former value.

I'm using Windows 7 x64. Just updated to the latest DMD version. I'm compiling as an x86 Windows application. Got the most recent bindings and dlls.

I don't understand what's making this happen... any help would be very much appreciated.

Reply via email to