Class instance becoming null after calling bindings to C code???

Chirs Forest CF at chrisforest.com
Wed Nov 15 13:24:02 UTC 2017


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.



More information about the Digitalmars-d-learn mailing list