简体   繁体   English

通过Kryonet发送对象会导致崩溃

[英]Sending object over Kryonet causes crash

I'm trying to send objects using Kryonet. 我正在尝试使用Kryonet发送对象。 For most objects it works fine, but for my own Vector implementation it crashes. 对于大多数对象来说,它工作正常,但是对于我自己的Vector实现,它崩溃了。 The class is registered on both sides. 该课程在两面都注册。 It contains an empty constructor and all variables are decalred as public. 它包含一个空的构造函数,并且所有变量都被标为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. 将日志级别设置为TRACE时没有错误。 The application just calls the disconnected(....) method. 该应用程序仅调用断开连接(....)方法。 If I remove strictfp from the class definition it still doesn't work. 如果我从类定义中删除strictfp,它仍然不起作用。

The problem only occurs when I reference a StrictVector2f in another object and try to send that one. 仅当我在另一个对象中引用StrictVector2f并尝试发送该对象时,才会出现此问题。 Sending only a StrictVector2f works perfectly. 仅发送StrictVector2f可以正常工作。

If anyone runs into the same problem. 如果有人遇到同样的问题。 This crash happpens when some of the objects Kryo serializes are not setup correctly. 当某些未正确设置Kryo序列化的对象时,将发生此崩溃。 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. 确保您有一个空的构造函数,所有变量都是公共的,所有对象都以相同顺序注册在所有kryo对象上,并且如果在服务器和客户端中有多个对象,请检查相等。 That was my problem. 那是我的问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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