Facepunch / sbox-issues

177 stars 12 forks source link

`Morphs.Set()` on non-morphable models crashes s&box #6252

Closed PolSpock closed 3 months ago

PolSpock commented 3 months ago

Describe the bug

Hi,

If you attempt to set Morphs on a non-morphable model, s&box will crash. Of course, this operation is not expected to work, but the crash should still be avoided.

To Reproduce

1) Download https://github.com/Facepunch/sbox-scenestaging/issues 2) Edit Gun.cs as follows:

public sealed class Gun : Component
{
    [Property] public GameObject ObjectToSpawn { get; set; }

    protected override void OnUpdate()
    {
        if ( IsProxy )
            return;

        var pc = Components.GetInAncestors<PlayerController>();
        if ( pc is null )
            return;

        var lookDir = pc.EyeAngles.ToRotation();

        if ( Input.Pressed( "Attack1" ) )
        {
            var go = new GameObject();
            var skin = go.Components.Create<SkinnedModelRenderer>();
            // Non-morphable model
            skin.Model = Model.Load( "models/sbox_props/wooden_crate/wooden_crate.vmdl" );
            skin.SceneModel.Morphs.Set( 0, 1f );
        }
    }
}

3) Start networking.scene and press "attack1". 4) s&box crashes.

Expected behavior

s&box should never crash

Media/Files

No response

Additional context

No response

aylaylay commented 3 months ago

Fixed thanks