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

Chirs Forest CF at chrisforest.com
Wed Nov 15 15:37:51 UTC 2017


On Wednesday, 15 November 2017 at 13:30:14 UTC, Adam D. Ruppe 
wrote:
> On Wednesday, 15 November 2017 at 13:24:02 UTC, Chirs Forest 
> wrote:
>> class Audio {
>> Audio a;
>>     writeln(&a); // 281478
>
> &class is usually wrong. That's the address of the reference, 
> not of the actual object. You might want `cast(void*) a` 
> instead to print the address of the object itself.
>
>>     writeln(&a); // null
>
> Though why it would ever say null is weird. Maybe one of the 
> lengths you pass to a C function is wrong and it is writing too 
> far and killing one of the hidden thread local pointer 
> variables.

The problem isn't that it's printing null, the problem is that 
I'm getting an access violation at the points where writeln will 
return null. writeln(cast(void*)a) gives me slightly different 
results: It'll start off as null, print an address after the 
class has been created, and then print a different address after 
calling load().

I'm not passing any lengths... I'm passing a string, but the 
function doesn't take a string length (I'm using toStrings to 
make the cstring and I've tried adding \0 at the end of it too, 
but it doesn't help). The function takes a struct for options but 
is meant to take null if you're not doing anything special. 
Replacing that with a pointer to an instance of that struct will 
give me an access violation calling writeln(cast(void*)a) after 
load() (that struct takes the size of itself as its first member 
and that's set properly).

I'm not really sure what fmod is doing after I call it. Even 
calling the function to control volume messes with the class 
address... it might be messing with more than just that, so if 
it's possible for fmod to be overflowing into the context that 
called it, that's probably it.

Is there anything I can do about it or should i be contacting the 
fmod guys, or the derelict binding guys?


More information about the Digitalmars-d-learn mailing list