crosire / d3d8to9

A D3D8 pseudo-driver which converts API calls and bytecode shaders to equivalent D3D9 ones.
BSD 2-Clause "Simplified" License
880 stars 78 forks source link

Update Ref Count #46

Closed elishacloud closed 6 years ago

elishacloud commented 6 years ago

This update will fix a couple of issues with the reference counter. This fixes the crash in GTA III/VC when changing resolutions and the crash in Serious Sam 1 & 2 when pressing alt+tab.

There are several fixes in this update:

  1. This update stops adding a reference the constructor and releasing the reference in each destructor.

These extra references are not needed. Plus they complicate the code and masks other issues (see below). Also it seems like d3d8to9 does not always close out all the references here, though I cannot prove this. This seems to be the main issue because the reason the games were crashing is because the previous device was still open and the reason the previous device was still open was because there were extra references on it.

  1. This update stops releasing a reference after calling GetType() in the GetTexture() function.

This extra Release() would have been causing a crash in many games but since we added the extra reference in the constructor (see above) this issue was being masked. The documentation here, here and everywhere else I have looked says nothing about GetType() adding a reference counter. From my testing GetType() never adds a reference counter. So we should not have a Release() in the GetTexture() function.

  1. This update no longer removes the object from the address cache in the destructor.

All the objects are removed only when the device is removed, to mirror Direct3D9's behavior. Therefore we don't need to remove the cache because it will already get removed by the AddressLookupTable destructor here.

  1. This update removes the previous workaround for the lost device see here

We no longer need that extra code for resetting the device now that the reference counter is corrected. That was really only fixing the symptom not the root issue.

crosire commented 6 years ago

Awesome!