简体   繁体   中英

Sending object over Kryonet causes crash

I'm trying to send objects using Kryonet. For most objects it works fine, but for my own Vector implementation it crashes. The class is registered on both sides. It contains an empty constructor and all variables are decalred as public.

public strictfp class StrictVector2f implements StrictVector
{
    public double x;
    public double y;

    public StrictVector2f()
    {

    }

    public StrictVector2f(double x, double y)
    {
        this.x = x;
        this.y = y;
    }

    public StrictVector2f(StrictVector2f src)
    {
        this.x = src.x;
        this.y = src.y;
    }

    public StrictVector2f(Vector2f src)
    {
        this.x = src.x;
        this.y = src.y;
    }

    public StrictVector2f add(StrictVector2f r)
    {
        return new StrictVector2f(this.x + r.x, this.y + r.y);
    }

    public StrictVector2f sub(StrictVector2f r)
    {
        return new StrictVector2f(this.x - r.x, this.y - r.y);
    }


    @Override
    public String toString()
    {
        return "StrictVector2f: [" + x + "|" + y + "]";
    }
}

No error is given when I set the log level to TRACE. The application just calls the disconnected(....) method. If I remove strictfp from the class definition it still doesn't work.

The problem only occurs when I reference a StrictVector2f in another object and try to send that one. Sending only a StrictVector2f works perfectly.

If anyone runs into the same problem. This crash happpens when some of the objects Kryo serializes are not setup correctly. Make sure you have an empty constructor, all variables are public, all objects are registered on all kryo objects in the same order and if you have multiple objects in eg server and client, CHECK THE ARE EQUAL. That was my problem.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM