Skip to content

Crash when accessing Entity.physics_object #357

Description

@vinci6k

While messing around with props in HL2DM, it appears I stumbled upon an issue related to the internal caching system. The server crashes when you try to get the PhysicsObject of a prop_physics_respawnable entity after it respawns. Here's the code I used:

# ../physics_object_test/physics_object_test.py

# Source.Python
from commands import CommandReturn
from commands.client import ClientCommand
from entities.constants import MoveType
from mathlib import Vector
from players.entity import Player


FORCE = Vector(0, 0, 500)


@ClientCommand('push_up')
def push_up_cmd(command, index):
    player = Player(index)
    entity = player.view_entity

    # Is this a physical object?
    if entity.move_type == MoveType.VPHYSICS:
        # Push it up.
        entity.physics_object.apply_force_center(
            FORCE * entity.physics_object.mass)
    
    return CommandReturn.BLOCK

Basically, use the push_up command on any breakable prop, destroy it, and when it respawns - use the command again. This will result in a crash (https://www.youtube.com/watch?v=xFOaoMnlcNI - got lucky in the video, usually it crashes after the first respawn).

As for why I believe this to be an issue with the internal caching system - the entity (prop_physics_respawnable) doesn't get removed when it's destroyed, just hidden. Which means the entity itself is always within the cache. Here's the catch though, the PhysicsObject tied to the entity does get removed - as can be seen in CPhysicsPropRespawnable::Event_Killed(). Thus the physics_object property no longer points at the correct instance.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions