"This NativeObject is not registered in this NativeObjectManager"

I’m having this problem intermittently when attempting to switch to an app to fullscreen.

The only results for this error while searching google was the svn code in NativeObjectManager.java so I guess it must not be a common error…

SEVERE: Uncaught exception thrown in Thread[LWJGL Renderer Thread,5,main] java.lang.IllegalArgumentException: This NativeObject is not registered in this NativeObjectManager at com.jme3.util.NativeObjectManager.deleteNativeObject(NativeObjectManager.java:136) at com.jme3.util.NativeObjectManager.deleteUnused(NativeObjectManager.java:188) at com.jme3.renderer.lwjgl.LwjglRenderer.onFrame(LwjglRenderer.java:759) at com.jme3.system.lwjgl.LwjglAbstractDisplay.runLoop(LwjglAbstractDisplay.java:187) at com.jme3.system.lwjgl.LwjglDisplay.runLoop(LwjglDisplay.java:185) at com.jme3.system.lwjgl.LwjglAbstractDisplay.run(LwjglAbstractDisplay.java:228) at java.lang.Thread.run(Thread.java:724)

I’ve been struggling with this for hours attempting to find a way to reproduce this error consistently… but to no success.

Unfortunately I’ve also been unable to reproduce these results in a simple test case. Really, the only difference there could be is that within my game there is a few Picture spatials attached to the guiNode… so I’m not sure why I can’t reproduce it outside of my game (I’m not using an old .dll or something - already checked that).

This is the bare minimum amount of code (within my game) that I can use to reproduce the error… (but as mentioned, outside of my game I can’t reproduce it with this)
I MUST call toggleSettingsMenu(false) and I believe that I also need to turn AA on (very odd behavior… my best guess is some sort of threading issue??)
[java]
toggleSettingsMenu(false);
game.settings.setSamples(4);
game.settings.setFullscreen(true);
game.setSettings(game.settings);
game.restart();
[/java]

toggleSettingsMenu simply repositions and hides some spatials:
[java]
private void toggleSettingsMenu(boolean active){
if(active){
settingsMenu.setCullHint(CullHint.Never);
titleButton1.setText(“Apply”);
titleButton2.setText(“Cancel”);
titleButton1.setLocalTranslation((game.settings.getWidth() / 2) - (titleButton1.getWidth() / 2) - 80, (game.settings.getHeight() / 2) - 180, -1);
titleSeparator1.setLocalTranslation((game.settings.getWidth() / 2) - (titleSeparator1.getWidth() / 2) - 5, (game.settings.getHeight() / 2) - 180, -1);
titleButton2.setLocalTranslation((game.settings.getWidth() / 2) - (titleButton2.getWidth() / 2) + 80, (game.settings.getHeight() / 2) - 180, -1);
titleButton3.setCullHint(CullHint.Always);
titleSeparator2.setCullHint(CullHint.Always);
} else {
settingsMenu.setCullHint(CullHint.Always);
titleButton1.setText(“Start”);
titleButton2.setText(“Settings”);
titleButton1.setLocalTranslation((game.settings.getWidth() / 2) - (titleButton1.getWidth() / 2) - 160, (game.settings.getHeight() / 2) - 180, -1);
titleSeparator1.setLocalTranslation((game.settings.getWidth() / 2) - (titleSeparator1.getWidth() / 2) - 95, (game.settings.getHeight() / 2) - 180, -1);
titleButton2.setLocalTranslation((game.settings.getWidth() / 2) - (titleButton2.getWidth() / 2), (game.settings.getHeight() / 2) - 180, -1);
titleButton3.setCullHint(CullHint.Never);
titleSeparator2.setCullHint(CullHint.Never);
}
}
[/java]

The code is called within an AppState (the title menu for my game) I add a KeyTrigger mapping and execute the code from the ActionListener.

I understand that it is problematic that I can not reproduce this error consistently (or put together a small test app) and it doesn’t help you guys much… but I’ve been at this for hours and don’t really even have a lead as to what t he problem might be. So I’m hoping that somebody has some ideas as to what might cause this type of error (e.g. not being thread-safe or something)

If this is not enough information for somebody to help me then I’ll have to just keep testing and will post any new information here.

Just making wild stabs…

Do you do things from other threads? (You mentioned threading so I had to ask.)

Do you remove things from the scene graph that you then add back later after switching to/from full screen?

Are you running a pure release or has it been updated to the latest stable build? (You may also try a nightly build.) I know there was some back-and-forth with native object management that was busted briefly and should be fixed in later code.

<cite>@pspeed said:</cite> Just making wild stabs...

Do you do things from other threads? (You mentioned threading so I had to ask.)

Do you remove things from the scene graph that you then add back later after switching to/from full screen?

Are you running a pure release or has it been updated to the latest stable build? (You may also try a nightly build.) I know there was some back-and-forth with native object management that was busted briefly and should be fixed in later code.

At the moment I only initialize/attach spatials in “simpleInitApp” (of SimpleApplication) and “initialize” (of AppState.)

Spatials are otherwise modified (culled, moved etc, but none added or removed at the moment) in “simpleUpdate” (of SimpleApplication) “update” (of AppState) and the ActionListener (of AppState). No other threads are involved. (are simpleInitApp, initialize and ActionListener on the update thread or thread-safe?)

toggleSettingsMenu is the biggest mystery for me as there is never an error unless I have that code right before I go fullscreen and it’s just moving/culling a few spatials.

I’m using the latest code from svn checkout. Currently http://www.jmonkeyengine.org/nightly/ says File not found (has since yesterday I believe). I’ll try some different builds to see if it fixes the problem.

note: It can take anywhere from 5-10+ tries before the error shows up.

I’ve tried the builds from /trunk/engine and /branches/3.0final/engine (is this the location of the stable build? I’m not a heavy user of svn ;)) with the same results.

@Clifton said: toggleSettingsMenu is the biggest mystery for me as there is never an error unless I have that code right before I go fullscreen and it's just moving/culling a few spatials.

…so what are those things exactly?

<cite>@pspeed said:</cite> ...so what are those things exactly?

[java]
settingsMenu.setCullHint(CullHint.Always);
titleButton1.setText(“Start”);
titleButton2.setText(“Settings”);
titleButton1.setLocalTranslation((game.settings.getWidth() / 2) - (titleButton1.getWidth() / 2) - 160, (game.settings.getHeight() / 2) - 180, -1);
titleSeparator1.setLocalTranslation((game.settings.getWidth() / 2) - (titleSeparator1.getWidth() / 2) - 95, (game.settings.getHeight() / 2) - 180, -1);
titleButton2.setLocalTranslation((game.settings.getWidth() / 2) - (titleButton2.getWidth() / 2), (game.settings.getHeight() / 2) - 180, -1);
titleButton3.setCullHint(CullHint.Never);
titleSeparator2.setCullHint(CullHint.Never);
[/java]

They are all Picture spatials, for the buttons I extend the Picture class and have a few methods (e.g. setText) which draw text onto a texture and set it to the Picture (currently using this to easily draw True Type Fonts.

I’ll be trying today to narrow it down to the least amount of code possible while still being able to reproduce the error, so hopefully I’ll be able to share some new information soon 8)

@pspeed

I managed to find a way to reproduce the behavior 100% of the time (but only on my computer… for some reason) by doing a very specific sequence of actions within my game. (sooooo strange…)

I believe I may have finally narrowed it down to the loading of a font:
[java]
try {
InputStream is = getClass().getResourceAsStream("/Interface/Fonts/carbona.ttf");
Font font = Font.createFont(Font.TRUETYPE_FONT, is);
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
ge.registerFont(font);
} catch(Exception e){
e.printStackTrace();
System.err.println(“Error loading font: carbona.”);
}
[/java]

Removing this code may have just changed when the error appears, so I’m very cautious about concluding that this is the problematic code… but I think it may be a good start.

The above font is used for drawing on a Picture’s texture. example:
[java]
Picture myPicture = new Picture(“MyPicture”);
myPicture.setWidth(200);
myPicture.setHeight(20);

 // initialize image and draw font onto it
BufferedImage img = new BufferedImage(200, 20, BufferedImage.TYPE_INT_ARGB);
Graphics2D g2 = (Graphics2D) img.getGraphics();
g2.setColor(Color.BLACK);
g2.setFont(new Font("carbona", Font.PLAIN, 12));
g2.drawString("My Text", 0, 14);
g2.dispose();

// create a new texture and set it's image to the image we just drew on
Texture2D texture = new Texture2D();
texture.setImage(new AWTLoader().load(img, true));

// set the picture's texture to the one we just created
myPicture.setTexture(assetManager, texture, true);

[/java]

*p.s. sry for double posting, did not know if it would be seen otherwise

Edit: nevermind… it still does it :frowning: Maybe it’s not specifically the font… but the drawing on the texture stuff using bufferedimage… hmmmmmm

Maybe try passing the image to the constructor instead of setting it after the fact on the Texture2D… that way there isn’t a image turned immediately to garbage.