【问题标题】:jMonkeyEngine: flyCam and inputManager both return NULLjMonkeyEngine:flyCam 和 inputManager 都返回 NULL
【发布时间】:2016-09-13 16:34:48
【问题描述】:

我遇到了一个问题:simpleInitApp() 中的 flyCam 和 inputManager 突然都变成了 NULL。

我不明白发生了什么!他们总是为空!

public void simpleInitApp() {
        Box b = new Box(1, 1, 1);
        System.out.println("inputManager = " + inputManager + "; flyCam = " + flyCam);
        Geometry geom = new Geometry("Box", b);

        Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
        mat.setColor("Color", ColorRGBA.Blue);
        geom.setMaterial(mat);

        rootNode.attachChild(geom);
    }

输出:inputManager = null; flyCam = null

我所有的示例(我通过 jMonkey Book 做了很多示例)现在都抛出 NullPointer 异常(它们以前工作过)。

我尝试过:

  1. 重新安装 jMonkey SDK 并清理 Windows 注册表
  2. 重新安装视频驱动程序

...没有任何帮助...

我不明白我到底做了什么……据我所知,我刚刚写过这个:

private final InputListener flyCamListener = new ActionListener() {
        @Override
        public void onAction(String name, boolean isPressed, float tpf) {
            boolean enabled = app.getFlyByCamera().isEnabled();
            app.getFlyByCamera().setEnabled(!enabled);
        }
    };

一切都粉碎了。

===

jMonkey 3.0.10_x86,Java:1.7.0_51,Windows 7 x86,OpenGL:3.0.0,GLSL 版本:1.30 - Intel Build 8.15.10.2342

【问题讨论】:

  • 如果你不初始化FlyCamAppState(例如不使用SimpleApplication的默认构造函数)flyCam将为NULL。如果您将配置中的“UseInput”设置为 false,inputManager 将为 NULL。

标签: java jmonkeyengine


【解决方案1】:

我想我解决了这个问题。在我发现并包含在新项目中的一个论坛上,这样的部分:

    Main app = new Main();
    AppSettings settings = new AppSettings(true);
    settings.setRenderer(AppSettings.LWJGL_OPENGL_ANY);
    settings.setResolution(640, 480);
    settings.setFrameRate(30);
    app.setSettings(settings);
    app.start();

...一切都开始工作了!包括我之前意外开始崩溃的所有应用程序。

所以我认为关键点是 setRenderer() 方法。我记得我在没有这样一行的情况下启动了我的灾难性应用程序,并且可能 jMonkey 为了它自己而“保存”了设置。

那么,为什么 jMonkey 会全局且永久地保留其不稳定的设置?所有其他应用程序崩溃,重新安装 SDK 无济于事等等!

【讨论】:

  • 您称之为“灾难性”的应用程序将其设置保存为“默认”。使用“new AppSettings(true)”(此处为 true 表示“使用默认设置”)的任何其他应用程序都将使用该设置。这就是为什么在会话之间保存分辨率首选项等的原因。记住它的不是 jme 或 SDK 本身,而是设置。
  • 你说得对,reden。在我看来,最好的解决方案是始终设置设置而不依赖默认值
猜你喜欢
  • 2015-02-22
  • 1970-01-01
  • 2017-10-07
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-05-22
  • 1970-01-01
相关资源
最近更新 更多