Cannot load a TextureAtlas file in IOS using libgd

2020-07-22 19:31发布

问题:

I started porting my LIBGDX appliction to IOS. I Used Xamarin studio port of libgdx to run my application on IOS. I was successful in porting but the application failed to load the TextureAtlas File & BitmapFont File in Iphone Simulator.

the code I tried was

   ...
    AssetManager assetManager = new AssetManager();
    assetManager.load("packer/help.txt", TextureAtlas.class);

    if (assetManager.update()) {

    }
    ...

The above code is running fine for me on Desktop and android but while running it on Iphone Simulator I got the following log.

Unhandled Exception:
0   iosgame                             0x000f4f7e mono_handle_exception_internal_first_pass + 2190
1   iosgame                             0x000f69c2 mono_handle_exception_internal + 1602
2   iosgame                             0x000f750f mono_handle_exception + 47
3   iosgame                             0x0013a662 mono_x86_throw_exception + 306
4   ???                                 0x0b730f8f 0x0 + 192089999
at com.badlogic.gdx.assets.AssetManager.update () [0x0009c] in /Users/badlogic/jenkins/workspace/libgdx-mac/gdx/src//com/badlogic/gdx/assets/AssetManager.java:346
at (wrapper synchronized) com.badlogic.gdx.assets.AssetManager.update () <IL 0x00009, 0x0002c>
at com.racing.gold.Screen.SplashScreen.update (single) [0x0001f] in /Users/Vikalp/Downloads/libgdx-nightly-20130609/Generated Project/my-gdx-game/src/com/racing/gold/Screen/SplashScreen.java:80
at com.racing.gold.Game.render () [0x0000d] in /Users/Vikalp/Downloads/libgdx-nightly-20130609/Generated Project/my-gdx-game/src/com/racing/gold/Game.java:48

at (wrapper managed-to-native) MonoTouch.UIKit.UIApplication.UIApplicationMain (int,string[],intptr,intptr) <IL 0x00056, 0x000a4>
at MonoTouch.UIKit.UIApplication.Main (string[],string,string) [0x0004c] in /Developer/MonoTouch/Source/monotouch/src/UIKit/UIApplication.cs:38
at com.ios.temp.project.Application.Main (string[]) [0x00000] in /Users/Vikalp/Downloads/libgdx-nightly-20130609/Generated Project/my-gdx-game-ios/Main.cs:33
at (wrapper runtime-invoke) <Module>.runtime_invoke_void_object (object,intptr,intptr,intptr) <IL 0x00049, 0x00077>
30  iosgame                             0x0006f462 mono_jit_runtime_invoke + 722
31  iosgame                             0x001d34de mono_runtime_invoke + 126
32  iosgame                             0x001d76d4 mono_runtime_exec_main + 420
33  iosgame                             0x001dcac5 mono_runtime_run_main + 725
34  iosgame                             0x000ccb65 mono_jit_exec + 149
35  iosgame                             0x0026b494 main + 1988
36  iosgame                             0x00068269 start + 53

2013-06-11 09:51:47.694 iosgame[567:c07] Unhandled managed exception: java.net.MalformedURLException: unknown protocol: file (com.badlogic.gdx.utils.GdxRuntimeException)
  at com.badlogic.gdx.assets.AssetManager.handleTaskError (System.Exception t) [0x000bf] in /Users/badlogic/jenkins/workspace/libgdx-mac/gdx/src//com/badlogic/gdx/assets/AssetManager.java:512 
  at com.badlogic.gdx.assets.AssetManager.update () [0x0009c] in /Users/badlogic/jenkins/workspace/libgdx-mac/gdx/src//com/badlogic/gdx/assets/AssetManager.java:346 
  at (wrapper synchronized) com.badlogic.gdx.assets.AssetManager:update ()
  at com.racing.gold.Screen.SplashScreen.update (Single deltaTime) [0x0001f] in /Users/Vikalp/Downloads/libgdx-nightly-20130609/Generated Project/my-gdx-game/src/com/racing/gold/Screen/SplashScreen.java:80 
  at com.racing.gold.Game.render () [0x0000d] in /Users/Vikalp/Downloads/libgdx-nightly-20130609/Generated Project/my-gdx-game/src/com/racing/gold/Game.java:48 
  at com.badlogic.gdx.backends.ios.IOSGraphics.OnRenderFrame (OpenTK.FrameEventArgs arg0) [0x00184] in /Users/badlogic/jenkins/workspace/libgdx-mac/backends/gdx-backend-iosmonotouch/src//com/badlogic/gdx/backends/ios/IOSGraphics.java:185 
  at OpenTK.Platform.iPhoneOS.iPhoneOSGameView.RunIteration () [0x000c1] in /Developer/MonoTouch/Source/monotouch/src/OpenGLES/OpenTK_1.0/Platform/iPhoneOS/iPhoneOSGameView.cs:830 
  at OpenTK.Platform.iPhoneOS.CADisplayLinkTimeSource.RunIteration () [0x00000] in /Developer/MonoTouch/Source/monotouch/src/OpenGLES/OpenTK_1.0/Platform/iPhoneOS/iPhoneOSGameView.cs:158 
  at (wrapper managed-to-native) MonoTouch.UIKit.UIApplication:UIApplicationMain (int,string[],intptr,intptr)
  at MonoTouch.UIKit.UIApplication.Main (System.String[] args, System.String principalClassName, System.String delegateClassName) [0x0004c] in /Developer/MonoTouch/Source/monotouch/src/UIKit/UIApplication.cs:38 
  at com.ios.temp.project.Application.Main (System.String[] args) [0x00000] in /Users/Vikalp/Downloads/libgdx-nightly-20130609/Generated Project/my-gdx-game-ios/Main.cs:33 

I Tried changing my pack extension from .txt to .pack but got the same output.

I wasn't able to find the solution on Libgdx forums. Please enlighten me on this problem.

回答1:

Hey I found the issue.

When we make an app run from Xamarin Studio it does not pack all the items. It leaves some of the files like text files, xmls etc. We need to mark them to include them in app. Mark all these Files to be added as Bundle Resource.



回答2:

According to this post on the Badlogic forum, there are a couple things that could be wrong:

  • You're using java.net APIs (probably not in your case)
  • You're using the Gdx.files.classpath to load some files
  • You didn't completely/correctly pack your assets into your build.

Read the Libgdx IOSWiki closely for caveats and to make sure you've set everything up correctly.

This (similar) question: libgdx on ios GdxRuntimeException couldn't load file was resolved because the PNG files were not correctly optimized. See the "PNG Optimization" section (and note specifically which Libgdx version you're using since it seems the behavior has changed).