On 14.02.2017 22:56, Stefan Dösinger wrote:
This fixes compilation on Visual Studio with native compiler exceptions.
Signed-off-by: Stefan Dösinger stefandoesinger@gmx.at
While you are just at it, please note that this code also contains a leak when the exception is triggered. Actually, it would probably be easier to test if the pointer is writeable in advance, and exit early without creating the surface at all.
I wouldn’t be the least bit surprised if Windows leaked in this situation as well. But I guess for the test it is relevant for Valgrind runs.
A pre-emptive
__TRY { *surface = NULL; } __EXCEPT_PAGE_FAULT { return E_INVALIDARG; }
before doing any work would be nicer, if it doesn’t have any unexpected side effects (e.g. Windows might keep *surface alone in some error conditions, which wouldn’t surprise me either).
Alex, can you look into fixing the leak?
2017-02-14 15:15 GMT-07:00 Stefan Dösinger stefandoesinger@gmx.at:
Yes, I'll look into it. Sorry for not noticing the leak before.
-Alex
Am 14.02.2017 um 22:29 schrieb Alex Henrie alexhenrie24@gmail.com:
Yes, I'll look into it. Sorry for not noticing the leak before.
Please port the test to ddraw2-7 as well, and in ddraw4 and ddraw7 test the IDirectDraw4/7 refcount after the create call that fails because of the invalid pointer. Windows might leak a reference. (If it does, I don’t think we want to upstream the test, but document this behaviour in a comment)
What happens if you have a create failure like DDERR_NOCOOPERATIVELEVELSET and an invalid pointer?
I've now run numerous tests on DirectDraw.
The following conditions do not result in an attempted write to the surface pointer: - Null surface descriptor (returns E_INVALIDARG) - Wrong surface descriptor size (returns E_INVALIDARG) - Unset cooperative level (returns DDERR_NOCOOPERATIVELEVELSET)
The following conditions do result in an attempted write to the surface pointer: - Tried to create explicit frontbuffer (returns DDERR_INVALIDCAPS if NULL was written to the surface pointer and E_INVALIDARG if the write failed) - Requested surface with zero width or zero height (returns E_INVALIDARG)
None of the above conditions increments the IDirectDraw7 refcount.
So, we can try to write NULL to the surface pointer before the explicit frontbuffer/backbuffer and zero width/height checks, and that should give us behavior that is indistinguishable from Windows.
-Alex