Skip to content

[Memory Leak] Flashlights from disconnected players never get cleaned up in multiplayer #179

@VocalOpal

Description

@VocalOpal

★ Describe the Bug
Was digging through the source and spotted a memory leak in the flashlight system. When a player disconnects their AreaLight objects are never deregistered from Veil's renderer, they just orphan in flashLightList2. In a long running multiplayer session with players frequently joining and leaving this will progressively tank performance.
Steps to Reproduce

Run a multiplayer server with the mod
Have players toggle flashlights on (R)
Have players disconnect and reconnect repeatedly
Monitor memory usage, it'll climb and never come back down

Expected Behavior
On disconnect, the player's AreaLight entries should be removed from flashLightList2 and properly deregistered from Veil's renderer.

★ Screenshots
N/A, memory leak, nothing visual to show

★ System Information
★ Desktop
Operating System: Windows 11 Pro for Workstations 64-bit

★ Hardware
Processor (CPU): Intel Core i5 10400F @ 2.90GHz
Memory (RAM): 32.0GB Dual-Channel DDR4
Graphics Card (GPU): NVIDIA GeForce RTX 2060 (EVGA) 2GB

★ Mods

SPB-Revamped
Fabric API
GeckoLib
Simple Voice Chat
Mod Menu

Additional Context
Root cause is in SPBRevampedClient.java, the ClientConnectionEvents.DISCONNECT handler only calls setFlashLightOn(false) client-side, never touches the actual Veil light objects. Fix would be cleaning up flashLightList2 entries and deregistering from Veil on disconnect.

Log File (If Applicable)
N/A

Note: I've identified the fix locally - the clearFlashlights() method needs to iterate through flashLightList2.values() and call removeLight() on each AreaLight before clearing the map.

// FIXED LOGIC:

public void clearFlashlights() {
    for (ArrayList<AreaLight> areaLightList : flashLightList2.values()) {
        for (AreaLight areaLight : areaLightList) {
            VeilRenderSystem.renderer().getDeferredRenderer().getLightRenderer()
                .removeLight(areaLight); // Actually remove from Veil
        }
    }
    this.flashLightList2.clear();
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions