Am Donnerstag, 8. September 2005 18:24 schrieb Oliver Stieber:
--- Stefan Dösinger stefandoesinger@gmx.at wrote:
Hi, I think I've found the cause of the Empire Earth crash. This is not a reference counting problem at all, Empire Earth releases the DirectDraw and Surface objects on purpose. This is what happens:
- EE creates a DDraw object
- It attaches a Complex Surface
- It sets up a D3D device for this Surface
- EE performs a Flip(NULL, 0x20) on the surface
- It Releases the DirectDraw object
- It Releases the surface
Wine releases the surface in 5), Windows doesn't. It appears to me, that Windows doesn't release Surfaces which have a D3D object attached when the DDraw instance they belong to is freed.
I have written a small test app, which reproduces EEs behaviour. It crashes in Wine, but worksin Windows 2000. I'll do some more tests and submit a patch.
by the sound of things an internal reference is missing, up until 6 a reference should be kept, preventing the surface from being released at 5.
No, Wine frees all Surfaces attached to a DDraw object once the DDraw object is freed, no matter how many references the Surface has. Windows does the same for normal surfaces(I checked it), but as it looks not for D3D Surfaces.
If the surface doesn't have a D3D object attached, the above combination leeds to a crash even in Windows.
From the log: 0009:trace:ddraw:Main_DirectDraw_Release (0x7fe00430)->() decrementing from 2. 0009:trace:ddraw:Main_DirectDraw_Release (0x7fe00430)->() decrementing from 1. 0009:warn:ddraw:Main_DirectDrawSurface_ForceDestroy destroying surface 0x5e52f958 with refcnt 2 0009:trace:ddraw:gltex_final_release deleting texture with GL id 0. 0009:warn:ddraw:Main_DirectDrawSurface_ForceDestroy destroying surface 0x5e535ba8 with refcnt 2 0009:trace:ddraw:gltex_final_release deleting texture with GL id 0. 0009:warn:ddraw:Main_DirectDrawSurface_ForceDestroy destroying surface 0x5e535680 with refcnt 2 0009:trace:ddraw:gltex_final_release deleting texture with GL id 0. 0009:warn:ddraw:Main_DirectDrawSurface_ForceDestroy destroying surface 0x5e5352e0 with refcnt 2 0009:trace:ddraw:gltex_final_release deleting texture with GL id 0. 0009:warn:ddraw:Main_DirectDrawSurface_ForceDestroy destroying surface 0x5e54fb00 with refcnt 2 0009:trace:ddraw:gltex_final_release deleting texture with GL id 0. 0009:warn:ddraw:Main_DirectDrawSurface_ForceDestroy destroying surface 0x5e54f5d8 with refcnt 2 0009:trace:ddraw:gltex_final_release deleting texture with GL id 0. 0009:warn:ddraw:Main_DirectDrawSurface_ForceDestroy destroying surface 0x5e5650d8 with refcnt 2 0009:trace:ddraw:gltex_final_release deleting texture with GL id 0. 0009:warn:ddraw:Main_DirectDrawSurface_ForceDestroy destroying surface 0x5e564bb0 with refcnt 1 0009:trace:ddraw:gltex_final_release deleting texture with GL id 0. 0009:warn:ddraw:Main_DirectDrawSurface_ForceDestroy destroying surface 0x7fe04738 with refcnt 2 0009:trace:ddraw:DIB_DirectDrawSurface_free_dc Releasing DC for surface: 0x7fe04738 0009:warn:ddraw:Main_DirectDrawSurface_ForceDestroy destroying surface 0x7fe04398 with refcnt 1 0009:trace:ddraw:User_DirectDrawSurface_final_release waiting for update thread to terminate... 0009:trace:ddraw:User_DirectDrawSurface_final_release update thread terminated 0009:trace:ddraw:DIB_DirectDrawSurface_free_dc Releasing DC for surface: 0x7fe04398 0009:trace:ddraw:Main_DirectDraw_Release (0x7fe000e0)->() decrementing from 1. wine: Unhandled exception (thread 0009), starting debugger... ->Crash due to Releasing a surface attached to DDraw 0x7fe00430
There are a lot of surfaces attached, which are destroyed, and only the Complex surface with the D3D object should survive. Empire Earth also doesn't touch the other surfaces any more.
It's also fine that EE releases the DDraw instance here. It perfoms a lot of checks on a lot of things, and it initialises numerous DDraw objects, Surfaces and D3D objects and Releases them again to check if they are working.
Stefan