-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1
Am 2015-07-30 um 12:07 schrieb Aaryaman Vasishta:
d3drm_device_create_surfaces_from_clipper sets the clipper and primary surface, and init_device sets ddraw and d3drm first before anything else, so even if any of them fail d3drm_device_destroy will ensure they're destroyed. If I explicitly destroy ddraw, how should I handle destroying of ddraw in d3drm_device_destroy (if it's not destroyed at that point)?
The problem with the current way is that what init_device does if it fails is an implementation detail that the caller shouldn't know. Ideally nothing is ever changed when a function fails.
I see two options:
1) Make sure init_device doesn't set any objects in case of failure.
2) Always AddRef ddraw and render target in init_device and always (including the success case) release them in the caller.
I prefer the second one because that way you have a clear pairing of create/addref and release calls in both places. (d3drm1_CreateDeviceFromClipper create + release, and init_device Addref + d3drm_device_destroy Release).
I think I mentioned this before, but "init_device" and "d3drm_device_destroy" are inconsistent names. I recommend to rename "init_device" to "d3drm_device_init".