Skip to content

[BUG]: Door.Get(Room) compares incompatible wrapper and base types #433

Description

@liubili

Before You Report

  • I searched the existing LabAPI issues and could not find this report.

Version

1.1.7 on master (verified against the current Door.cs on GitHub).

Description

Door.Get(Room room) delegates to Door.Get(room.Base). The latter filters doors using:

List.Where(x => x.Rooms.First().Equals(roomId));

However, x.Rooms is a Room[], while roomId is a RoomIdentifier. Room does not override Equals, so this comparison is between distinct wrapper and base-object types. Consequently, normal doors do not match and the overload returns an empty sequence.

Additionally, the First() call is unsafe for door variants whose Rooms property is empty (the wrapper explicitly documents this for checkpoint subdoors).

To Reproduce

On a generated map, run the following from a plugin after room and door wrappers are initialized:

Room room = Room.List.First();
Door[] expected = room.Doors.ToArray();
Door[] actual = Door.Get(room).ToArray();

Log.Debug($"Expected at least one door: {expected.Length}; Door.Get(room): {actual.Length}");

For a room with doors, expected is non-empty while actual is empty. Depending on enumeration order and registered checkpoint subdoors, the lookup can also fail with an InvalidOperationException from First().

Expected Behavior

Door.Get(Room) and Door.Get(RoomIdentifier) should return the doors connected to the requested room without relying on a first room entry.

Proposed Fix

Compare the base room identity and handle all associated rooms, for example:

public static IEnumerable<Door> Get(RoomIdentifier roomId) =>
    List.Where(door => door.Rooms.Any(room => room.Base == roomId));

This also handles multi-room doors correctly and excludes empty-room variants safely.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingimportedImported to internal git

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions