• 12
• 12
• 9
• 10
• 13

# Removing Lights from LightCollection? (MDX - C#)

This topic is 4134 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I'm writing a little renderer in C# to hone my DirectX skills (at the moment, it's little more than a way to allow realtime manipulation of various small elements). At the moment, if I want to remove a light from the scene, I just do
deviceRendering.Lights.Enabled = false;
(Slightly convoluted method of getting to that line, but the idea is there). However, the deviceRendering.Lights.Count value shows that this doesn't remove it as such - it just stops it from being taken into account for rendering. Is there a way to remove the light properly from the LightCollection? I can't seem to find one, which seems odd unless this is not how the lights are designed to be used (as otherwise, the lights will always consume MaximumNumberOfLightsAllocatedSoFar * sizeof(Light) regardless of how many lights are actively in use at that time (although this memory is reused if a light is added back in) - leaking memory).

##### Share on other sites
Disabling the light should be the way to go. The lights collection is a stub for working with the unmanaged SetLight() and is filled with some number of default light structs to make it easier to set up lighting. You can just use and reuse these default structs (so device.Lights[0] for example) by setting their properties and calling Update() on them to set them on the device. With this approach the number of lights stays constant, so no memory is leaked. I think this is how Managed lights are meant to be used, at least I've never had to allocate new lights myself.

Hope this helps :)

##### Share on other sites
Great, thanks. :) Just wasn't quite sure if I was going about that the right way. ;)