On Wed, Jun 29, 2016 at 7:21 PM, Henri Verbeet <hverbeet@gmail.com> wrote:
On 24 June 2016 at 23:49, Aaryaman Vasishta <jem456.vasishta@gmail.com> wrote:
>  HRESULT d3drm_device_set_ddraw_device_d3d(struct d3drm_device *device, IDirect3DRM *d3drm, IDirect3D *d3d, IDirect3DDevice *d3d_device)
>  {
> +    IDirectDrawSurface *surface;
> +    IDirect3DDevice2 *d3d_device2;
> +    DDSURFACEDESC desc;
> +    HRESULT hr;
> +
>      device->d3drm = d3drm;
>      IDirect3DRM_AddRef(d3drm);
>      device->device = d3d_device;
>      IDirect3DDevice_AddRef(d3d_device);
>
> +    /* Fetch render target and get width/height from there */
> +    if (FAILED(hr = IDirect3DDevice_QueryInterface(d3d_device, &IID_IDirectDrawSurface, (void **)&surface)))
> +    {
> +        if (FAILED(hr = IDirect3DDevice_QueryInterface(d3d_device, &IID_IDirect3DDevice2, (void **)&d3d_device2)))
> +            return hr;
> +        hr = IDirect3DDevice2_GetRenderTarget(d3d_device2, &surface);
> +        IDirect3DDevice2_Release(d3d_device2);
> +        if (FAILED(hr))
> +            return hr;
> +    }
> +
> +    desc.dwSize = sizeof(desc);
> +    if (FAILED(hr = IDirectDrawSurface_GetSurfaceDesc(surface, &desc)))
> +    {
> +        IDirectDrawSurface_Release(surface);
> +        return hr;
> +    }
> +
> +    device->width = desc.dwWidth;
> +    device->height = desc.dwHeight;
> +    IDirectDrawSurface_Release(surface);
> +
>      return IDirect3D_QueryInterface(d3d, &IID_IDirectDraw, (void **)&device->ddraw);
>  }
>
This leaks some references (IDirect3DRM, IDirect3DDevice) on error
paths, are those on purpose?

This is a helper function, so the caller would be handling the references. See CreateDeviceFromD3D in device.c.

Cheers,
Aaryaman