From: Myah Caron qsniyg@protonmail.com
--- dlls/ddraw/ddraw_private.h | 1 + dlls/ddraw/device.c | 10 +--------- dlls/ddraw/executebuffer.c | 29 ++++++++++++----------------- 3 files changed, 14 insertions(+), 26 deletions(-)
diff --git a/dlls/ddraw/ddraw_private.h b/dlls/ddraw/ddraw_private.h index 912813ccc48..889a64219e5 100644 --- a/dlls/ddraw/ddraw_private.h +++ b/dlls/ddraw/ddraw_private.h @@ -339,6 +339,7 @@ struct d3d_device /* Pick data */ D3DPICKRECORD *pick_records; DWORD pick_record_count; + DWORD pick_record_size;
/* Required to keep track which of two available texture blending modes in d3ddevice3 is used */ BOOL legacyTextureBlending; diff --git a/dlls/ddraw/device.c b/dlls/ddraw/device.c index ac4388ab639..5d850c53caf 100644 --- a/dlls/ddraw/device.c +++ b/dlls/ddraw/device.c @@ -349,8 +349,7 @@ static ULONG WINAPI d3d_device_inner_Release(IUnknown *iface) IDirect3DDevice3_DeleteViewport(&This->IDirect3DDevice3_iface, &vp->IDirect3DViewport3_iface); }
- /* Free pick records array if any are allocated */ - if (This->pick_record_count > 0) + if (This->pick_record_size > 0) free(This->pick_records);
TRACE("Releasing render target %p.\n", This->rt_iface); @@ -1099,10 +1098,6 @@ static HRESULT WINAPI d3d_device1_GetPickRecords(IDirect3DDevice *iface, { /* If we have a destination array and records to copy, copy them now */ memcpy(records, device->pick_records, sizeof(*device->pick_records) * device->pick_record_count); - - /* We're now done with the old pick records and can free them */ - free(device->pick_records); - device->pick_record_count = 0; }
wined3d_mutex_unlock(); @@ -6942,9 +6937,6 @@ static HRESULT d3d_device_init(struct d3d_device *device, struct ddraw *ddraw, c
ddraw->d3ddevice = device;
- /* Initialize pick records array */ - device->pick_record_count = 0; - wined3d_stateblock_set_render_state(ddraw->state, WINED3D_RS_ZENABLE, d3d_device_update_depth_stencil(device)); if (version == 1) /* Color keying is initially enabled for version 1 devices. */ diff --git a/dlls/ddraw/executebuffer.c b/dlls/ddraw/executebuffer.c index bc95b3e2a82..99cd5710d7d 100644 --- a/dlls/ddraw/executebuffer.c +++ b/dlls/ddraw/executebuffer.c @@ -143,12 +143,7 @@ HRESULT d3d_execute_buffer_execute(struct d3d_execute_buffer *buffer, struct d3d const unsigned int vertex_size = get_flexible_vertex_size(D3DFVF_TLVERTEX); D3DTLVERTEX verts[TRIANGLE_SIZE];
- /* Check for any un-freed pick records */ - if (device->pick_record_count > 0) - { - free(device->pick_records); - device->pick_record_count = 0; - } + device->pick_record_count = 0;
TRACE("ExecuteData :\n"); if (TRACE_ON(ddraw)) @@ -325,17 +320,21 @@ HRESULT d3d_execute_buffer_execute(struct d3d_execute_buffer *buffer, struct d3d { D3DPICKRECORD* record;
- /* Create new array to fit one more record */ - DWORD new_record_count = device->pick_record_count + 1; - D3DPICKRECORD* new_record_array = malloc(sizeof(*device->pick_records) * new_record_count); - if (device->pick_record_count > 0) + device->pick_record_count++; + + /* Grow the array if necessary */ + if (device->pick_record_count > device->pick_record_size) { - memcpy(new_record_array, device->pick_records, sizeof(*device->pick_records) * device->pick_record_count); - free(device->pick_records); + if (device->pick_record_size == 0) + device->pick_record_size = 1; + else + device->pick_record_size *= 2; + device->pick_records = realloc(device->pick_records, + sizeof(*device->pick_records) * device->pick_record_size); }
/* Fill record parameters */ - record = &new_record_array[device->pick_record_count]; + record = &device->pick_records[device->pick_record_count - 1];
record->bOpcode = current->bOpcode; record->bPad = 0; @@ -346,10 +345,6 @@ HRESULT d3d_execute_buffer_execute(struct d3d_execute_buffer *buffer, struct d3d /* Formula for returning the Z value at this X/Y */ record->dvZ = d3d_execute_buffer_z_value_at_coords(pick_rect->x1, pick_rect->y1, verts);
- /* Point device info to new record information */ - device->pick_records = new_record_array; - device->pick_record_count = new_record_count; - /* We have a successful pick so we can skip the rest of the triangles */ instr += size * (count - i - 1); count = i;