wiremod / wire

Garry's Mod add-on that allows users to wire up components in order to make more elaborate automatic and user-controlled contraptions.
http://www.wiremod.com
Apache License 2.0
556 stars 334 forks source link

Quaternions in E2 causing server crash. #222

Closed RevoluPowered closed 11 years ago

RevoluPowered commented 11 years ago

I ran this expression on a multiplayer server as I am developing a forklift for moving stuff in spacebuild, It uses prop core.

When i executed the chip it didn't crash only after I got into the chair. As you would expect due to the code.

@name Forklift
@inputs Forklift:entity
@outputs
@persist RelativeRotation:quaternion LastPitch:number LastYaw:number
@trigger

interval( 100 )

if( first() )
{
    Forklift:propGravity(0)
    #
    # Driver Code.
    #

    # do we actually have a driver in the seat.
    function number hasDriver()
    {
        return Forklift:driver():isValid()
    }

    # return the entity driver.
    function entity getDriver()
    {
        return Forklift:driver()
    }

    #
    # Camera Movement Detection
    #

    function number getDeltaPitch( Player:entity )
    {
        local CurrentPitch = Player:eye():x()
        local Delta = LastPitch - CurrentPitch
        LastPitch = CurrentPitch
        return Delta
    }

    function number getDeltaYaw( Player:entity )
    {
        local CurrentYaw = Player:eye():y()
        local Delta = LastYaw - CurrentYaw
        LastYaw = CurrentYaw
        return Delta
    }

    #
    # Default variable assignment
    #

    RelativeRotation = quat()

    #
    # Rotation Functions
    #

    function quaternion getRotation()
    {
        return quat( Forklift:angles() )   
    }

    function void setRotation( Rotation:quaternion )
    {
        RelativeRotation += Rotation
        Forklift:setAng( Rotation:toAngle() )
    }

    function quaternion getRelative()
    {
        return RelativeRotation
    }
}

# Do we have a driver.
if( hasDriver() )
{
    # Driver assignment.
    local Driver = getDriver()
    local Rotation = getRotation()

    local Pitch = getDeltaPitch( Driver )
    local Yaw = getDeltaYaw( Driver )

    setRotation( slerp( RelativeRotation, RelativeRotation, 1 ) )
    #setRotation( slerp( getRotation() + getRelative(), getRotation() + getRelative() + Rotation, 0.1 ))
    #setRotation( getRelative() * PitchQ )

}
RevoluPowered commented 11 years ago

The z component on quat:toAngles() is nan.

Relative rotation is [ 90,0,nan ] when i use toAngles()

neb is taking a look.

RevoluPowered commented 11 years ago

Same issue stands when multiplying somequat * quat:up()

It probably happens with the other directions too.

Divran commented 11 years ago

It doesn't matter if any of the numbers in the quat or the angle you get from quat:toAngle() is infinity, because Lua can handle that just fine. The problem only occurred if you tried to stuff infinity into setAngle, which Nebual has already added a check for.

RevoluPowered commented 11 years ago

Right so its probably going to be something else fucked. Il take a look. On 8 Feb 2013 11:54, "Divran" notifications@github.com wrote:

It doesn't matter if any of the numbers in the quat or the angle you get from quat:toAngle() is infinity, because Lua can handle that just fine. The problem only occurred if you tried to stuff infinity into setAngle, which Nebual has already added a check for.

— Reply to this email directly or view it on GitHubhttps://github.com/wiremod/wire/issues/222#issuecomment-13287316.