Am Mittwoch 15 November 2006 23:35 schrieb Markus Amsler:
Depends on [1]. This fixes all d3d8 implicit surface refcount problems.
if (This->parentDevice && ref == 1) { if (implicit) { IUnknown_AddRef(This->parentDevice); } else { /* This can only happen on device/swapchain destruction. * It avoids destructing the device again on release. */ This->parentDevice = NULL; }
I do not like the extra if(implicit here). An incorrect test shows that an AddRef on any object with refcount == 0 increases the device's refcount, no matter if its implicit or not:
CreateTexture(device.., &texture); /* increases device refcount */ AddRef(texture); /* no change in dev refcount*/ Release(texture); Release(texture); /* device refcount decremented */ AddRef(texture); /* device refcount incremented */ Release(texture); /* decremented again */
Currently our CreateTexture(surface, vertexbuffer, ...) increases the device refcount and initializes the refcount to 1. In my eyes it would be cleaner to init the refcount of everything to 0, and if the interface is not implicit AddRef it(from 0 to 1) in Create*. In AddRef, when increasing the refcount from to to 1, AddRef the device.
} else { /* This can only happen on device/swapchain destruction. * It avoids destructing the device again on release. */ This->parentDevice = NULL; }
}
This looks like pretty obscure magic in AddRef to me :-/ . Wouldn't it be cleaner to unset the parent device in d3d8device8::Release?
Stefan Dösinger wrote:
Currently our CreateTexture(surface, vertexbuffer, ...) increases the device refcount and initializes the refcount to 1. In my eyes it would be cleaner to init the refcount of everything to 0, and if the interface is not implicit AddRef it(from 0 to 1) in Create*. In AddRef, when increasing the refcount from to to 1, AddRef the device.
You're right. Besides, we have already enough bogus AddRef/Release calls. I tried to keep the changes as small as possible. Hey I simply wanna game BF1942 :-)