JPCT-AE error loading models (.md2, .3ds ...)[SOLVED]

Started by PaniX, September 15, 2013, 07:07:03 PM

Previous topic - Next topic

PaniX

Hello guys,
as I'm an Android and JPCT-AE noob, I have to ask something.
I'm currently playing a little bit around with the HelloWorld-AE example, and found a problem.
The normal
cube = Primitives.getCube(10.0f);
cube.calcTextureWrap();
cube.setTexture("texture");
cube.strip();
cube.build();

method works. But when I try to load my own Model instead, like this:
cube = Loader.loadMD2(getResource().openRawResource(R.raw.gun), 0.5f);
//cube = Primitives.getCube(10.0f);
cube.calcTextureWrap();
cube.setTexture("texture");
cube.strip();
cube.build();

the Application crashs. I'm not sure why, as it worked already for me. The same happens when I try to load a 3DS file, like it's written in the wiki.
Does someone knows what's the problem?
Thanks
PaniX

EgonOlsen

Impossible to tell unless you post the actual exception too.

PaniX

The logcat doesn't help either:

Android Log: Sep 16, 2013 06:21:28 +0200 - I/ActivityManager(  236): START {act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10304000 cmp=free.codeninja.theone/.MainActivity} from pid 314
I/ActivityManager(  236): Start proc free.codeninja.theone for activity free.codeninja.theone/.MainActivity: pid=1259 uid=10085 gids={}
I/ActivityManager(  236): Displayed free.codeninja.theone/.MainActivity: +657ms
E/AndroidRuntime( 1259): at free.codeninja.theone.MainActivity$MyRenderer.onSurfaceChanged(MainActivity.java:175)
W/ActivityManager(  236):   Force finishing activity free.codeninja.theone/.MainActivity
I/ActivityManager(  236): Process free.codeninja.theone (pid 1259) has died.

EgonOlsen

That can't be everything. Are you by any chance swallowing some exception in your code?

PaniX

May it be that there is something wrong with the inputstream? Not the object, I mean in the code? A wrong import? I'm not sure, but I think I've changed something in the imports.

EgonOlsen

Looks fine to me. Even if it's wrong, there should be more info than just start/exit.

PaniX

There is nothing more in the logcat. Maybe in the .xml files? Could there be a problem? I don't think so, because getCube works...

PaniX

#7
Made a Logger.log();
before cube = Loader.load [..]
It tells me that it fails loading the model, because the next Logger.log(); after Loader.loadMD2(); doesn't come (bad english, yay)
But I don't know what's wrong. Because I loaded the model before in JPCT-AE without any problems...
The model is in res/raw/gun.md2


09-16 14:54:43.977: I/jPCT-AE(2378): Loading model
09-16 14:54:44.007: W/dalvikvm(2378): threadid=11: thread exiting with uncaught exception (group=0x2b4e71f8)
09-16 14:54:44.007: E/AndroidRuntime(2378): FATAL EXCEPTION: GLThread 219

EgonOlsen

Try to put a try-catch around the loading code and log the exception.

EgonOlsen

...and make sure to catch Throwable, not just Exception.

PaniX

When I do it like this:
Logger.log("Loading model");
try {
cube = Loader.loadMD2(getResource().openRawResource(R.raw.gun), 0.5f);
Logger.log("Loaded model!");
}catch(Throwable e) {
Logger.log("ERROR:" + e.getMessage());
}


(not sure if this IS right, I'm new to Java)

It tells me this:

09-16 17:10:51.987: I/jPCT-AE(3728): Loading model
09-16 17:10:51.987: I/jPCT-AE(3728): ERROR:null
09-16 17:10:52.017: W/dalvikvm(3728): threadid=11: thread exiting with uncaught exception (group=0x2b4e71f8)
09-16 17:10:52.017: E/AndroidRuntime(3728): FATAL EXCEPTION: GLThread 366

Hopefully it helps :D

EgonOlsen

...not really. getMessage() on Exceptions often returns null. It would be better to simply do Logger.log(e); because that will print the actual stack trace.

PaniX


09-16 20:10:49.377: I/jPCT-AE(6202): Texture loaded...16384 bytes/64*64 pixels!
09-16 20:10:49.377: I/jPCT-AE(6202): Loading model
09-16 20:10:49.397: I/jPCT-AE(6202): [ 1379355049402 ] - ERROR: java.lang.NullPointerException
09-16 20:10:49.397: I/jPCT-AE(6202): at free.codeninja.theone.MainActivity$MyRenderer.onSurfaceChanged(MainActivity.java:177)
09-16 20:10:49.397: I/jPCT-AE(6202): at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1456)
09-16 20:10:49.397: I/jPCT-AE(6202): at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1217)
09-16 20:10:49.407: W/dalvikvm(6202): threadid=11: thread exiting with uncaught exception (group=0x2b4e71f8)
09-16 20:10:49.417: E/AndroidRuntime(6202): FATAL EXCEPTION: GLThread 627
09-16 20:10:49.417: E/AndroidRuntime(6202): java.lang.RuntimeException: [ 1379355049402 ] - ERROR: java.lang.NullPointerException
09-16 20:10:49.417: E/AndroidRuntime(6202): at free.codeninja.theone.MainActivity$MyRenderer.onSurfaceChanged(MainActivity.java:177)
09-16 20:10:49.417: E/AndroidRuntime(6202): at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1456)
09-16 20:10:49.417: E/AndroidRuntime(6202): at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1217)
09-16 20:10:49.417: E/AndroidRuntime(6202): at com.threed.jpct.Logger.log(Logger.java:189)
09-16 20:10:49.417: E/AndroidRuntime(6202): at com.threed.jpct.Logger.log(Logger.java:136)
09-16 20:10:49.417: E/AndroidRuntime(6202): at free.codeninja.theone.MainActivity$MyRenderer.onSurfaceChanged(MainActivity.java:180)
09-16 20:10:49.417: E/AndroidRuntime(6202): at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1456)
09-16 20:10:49.417: E/AndroidRuntime(6202): at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1217)
09-16 20:10:49.517: D/OpenGLRenderer(6202): Flushing caches (mode 0)
09-16 20:10:50.247: D/OpenGLRenderer(6202): Flushing caches (mode 1)
09-16 20:10:51.257: I/Process(6202): Sending signal. PID: 6202 SIG: 9

PaniX

Must be something wrong in the project setup. In the original HelloWorld-AE example (Android Application from Existing File) it works, in my project it doesn't work (Android Application Project)...
Where could the error be?

EgonOlsen

If this is line 177


cube = Loader.loadMD2(getResource().openRawResource(R.raw.gun), 0.5f);


then only getResource() may return null or R.raw is null. Both seem strange to me, but it might indicate a problem with your project setup. Just try to create a new from scratch and see if that helps.