[dx9-12] Major change to design

Ann and Jason Edmeades us at the-edmeades.demon.co.uk
Tue Oct 26 17:07:05 CDT 2004

>Looks much better yes, thanks. 


>There's still something strange here:
>> +    /* Not recording... */
>> +    if (oldSrc != NULL) {
>> +        IWineD3DVertexBuffer_Release(oldSrc);
>> +        IUnknown_Release((IUnknown *)((IWineD3DVertexBufferImpl
*)oldSrc)->resource.parent);  /* Released an internal reference to a VB */
>> +    }
>> +    if (pStreamData != NULL) {
>> +        IWineD3DVertexBuffer_AddRef(pStreamData);
>> +        IUnknown_AddRef((IUnknown *)((IWineD3DVertexBufferImpl
*)pStreamData)->resource.parent); /* Gained an internal reference to a VB */
>> +    }

>You shouldn't need to AddRef the parent, that's up to the object that
>holds the pointer (also you should do the AddRef before the Release in
>case old and new are the same object).

Well, that's where I come unstuck :-)

The problem is that in the caller, I could do the addref, but I cant do the
release because the caller doesn't know nor have access to (nor should know
/ have access to!) the vb which it is replacing. It made more 'sense' to do
both in the same place because it is then 'obvious' when one is wrong.

In this case (very pseudo code!)

D3D9 SetStreamSource (idx, d3d9_vb):
   Call WineD3D SetStreamSource(idx, d3d9_vb->wined3d_vb)

WineD3D SetStreamSource:
   In an array store the new vb and addref, and release the old one.

If I just addref/release the wined3d interface, I am not maintaining correct
reference counting for the d3d9 object (Think: Create, SetStreamSource,
Release. We would release the d3d9 one when we shouldn't).

The alternative is to pass back the thing I have freed, which is both very
unintuitive and also may cause problems later on when the same function
needs calling from within wined3d. It also means the caller needs to know
more of the internals whereas I have tried to keep the d3d9 code as trivial
as possible.

Suggestions welcome - I spent ages trying to get my head around how to keep
the dual reference counting correct, and that's the only model I cam up with
which worked!


More information about the wine-devel mailing list