diff --git a/dlls/ddraw/light.c b/dlls/ddraw/light.c index 22ebe2057f6..9c624f115bf 100644 --- a/dlls/ddraw/light.c +++ b/dlls/ddraw/light.c @@ -62,8 +62,6 @@ void light_activate(struct d3d_light *light) if (light->light.dwFlags & D3DLIGHT_ACTIVE) { viewport_alloc_active_light_index(light); - if (!light->active_light_index) - return; light_update(light); IDirect3DDevice7_LightEnable(&device->IDirect3DDevice7_iface, light->active_light_index, TRUE); } diff --git a/dlls/ddraw/viewport.c b/dlls/ddraw/viewport.c index 07fd197e0d0..e94c4b8da0e 100644 --- a/dlls/ddraw/viewport.c +++ b/dlls/ddraw/viewport.c @@ -135,9 +135,25 @@ void viewport_alloc_active_light_index(struct d3d_light *light) return; if (vp->active_lights_count >= DDRAW_MAX_ACTIVE_LIGHTS) - return; + { + struct d3d_light *l; + LIST_FOR_EACH_ENTRY(l, &vp->light_list, struct d3d_light, entry) + { + if (l->active_light_index) + { + WARN("Too many active lights, viewport %p, light %p, deactivating %p.\n", vp, light, l); + light_deactivate(l); + + /* Recycle active lights in a FIFO way. */ + list_remove(&light->entry); + list_add_tail(&vp->light_list, &light->entry); + break; + } + } + } map = vp->map_lights; + assert(vp->active_lights_count < DDRAW_MAX_ACTIVE_LIGHTS && map != ~0u); i = 0; while (map & 1) @@ -817,7 +833,7 @@ static HRESULT WINAPI d3d_viewport_AddLight(IDirect3DViewport3 *viewport, IDirec light_impl->active_viewport = vp; /* Add the light in the 'linked' chain */ - list_add_head(&vp->light_list, &light_impl->entry); + list_add_tail(&vp->light_list, &light_impl->entry); IDirect3DLight_AddRef(light); light_activate(light_impl);