Exception in NativeObjectManager

In NativeObjectManager around line 130, there is

[java]
if (ref2 == null) {
throw new IllegalArgumentException("This NativeObject is not " +
“registered in this NativeObjectManager”);
}

            assert ref == null || ref == ref2;

            int id = obj.getId();

            // Delete object from the GL driver
            obj.deleteObject(rendererObject);
            assert obj.getId() == NativeObject.INVALID_ID;

            if (logger.isLoggable(Level.FINEST)) {
                logger.log(Level.FINEST, "Deleted: {0}", obj.getClass().getSimpleName() + "/" + id);
            }

[/java]

The above code throws an exception which is hard to catch and process, because the object remover is almost always called through the system renderer, which is furthermore called automatically through the run thread on the GL surface. Since it’s not a very critical exception, I was wondering why it’s not done like this:

[java]
if (ref2 != null) {

                assert ref == null || ref == ref2;

                int id = obj.getId();

                // Delete object from the GL driver
                obj.deleteObject(rendererObject);
                assert obj.getId() == NativeObject.INVALID_ID;

                if (logger.isLoggable(Level.FINEST)) {
                    logger.log(Level.FINEST, "Deleted: {0}", obj.getClass().getSimpleName() + "/" + id);
                }

            } else {

                return false;

            }

[/java]

That way, the error can still be processed while the app keeps running.

Yes, but it’s a sign that your app has totally pooped the bed and then there is no sense continuing as you are now likely to get 100 strange errors. It’s a sign that something very bad has happened.

When encountering what is likely a catastrophically fatal error it is best to treat it fatally I guess.

1 Like

Well, that exception indicates the renderer tried to remove an object that a) is unused and b) isn’t even there. Failing at removing unneeded object that isn’t even there doesn’t seem much of a problem, and I haven’t got any other error / exception since I’ve applied the above change to my application.

@development said: Well, that exception indicates the renderer tried to remove an object that a) is unused and b) isn't even there. Failing at removing unneeded object that isn't even there doesn't seem much of a problem, and I haven't got any other error / exception since I've applied the above change to my application.

But what seriously bad thing happened to cause the renderer to have an invalid object in the first place? Memory corruption? Code using the wrong object for something?

In almost 3 years of JME development, I’ve never seen that error… so something is broken in your game and hiding it until it crops up somewhere else may not be the best way of dealing with it.

This issue was fixed: http://code.google.com/p/jmonkeyengine/source/detail?r=10889