This one has me a little stumped! I have 1 texture in my project which fails to load. I am using Monogame 3.2 and the XNA content pipeline. This issue only started happening when I ran my game on a Motorola Droid Razr (Android 4.1.1) emulator. It runs fine on a Galaxy S4 (Android 4.4) emulator.
I get the usual content error:
Microsoft.Xna.Framework.Content.ContentLoadException: Could not load Sprites\UI\InGame\winner01_black asset as a non-content file! ---> System.Exception: Opening stream error. ---> System.Exception:
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x00000] in <filename unknown>:0
at Android.Runtime.JNIEnv.CallIntMethod (IntPtr jobject, IntPtr jmethod, Android.Runtime.JValue[] parms) [0x00064] in /Users/builder/data/lanes/monodroid-mlion-monodroid-4.21-series/49a04b96/source/monodroid/src/Mono.Android/src/Runtime/JNIEnv.g.cs:369
at Java.IO.InputStream.Read (System.Byte[] buffer, Int32 offset, Int32 length) [0x0004a] in /Users/builder/data/lanes/monodroid-mlion-monodroid-4.21-series/49a04b96/source/monodroid/src/Mono.Android/platforms/android-15/src/generated/Java.IO.InputStream.cs:274
at Android.Runtime.InputStreamInvoker.Read (System.Byte[] buffer, Int32 offset, Int32 count) [0x00000] in /Users/builder/data/lanes/monodroid-mlion-monodroid-4.21-series/49a04b96/source/monodroid/src/Mono.Android/src/Runtime/InputStreamInvoker.cs:30
at System.IO.Stream.CopyTo (System.IO.Stream destination, Int32 bufferSize) [0x00000] in <filename unknown>:0
at System.IO.Stream.CopyTo (System.IO.Stream destination) [0x00000] in <filename unknown>:0
at Microsoft.Xna.Framework.Content.ContentManager.OpenStream (System.String assetName) [0x00024] in c:\Users\Matt\Documents\Dev\Game\MonoGame_3_2\MonoGame.Framework\Content\ContentManager.cs:251
at --- End of managed exception stack trace ---
at java.io.IOException:
at at android.content.res.AssetManager.readAsset(Native Method)
at at android.content.res.AssetManager.access$700(AssetManager.java:35)
at at android.content.res.AssetManager$AssetInputStream.read(AssetManager.java:576)
at at mono.java.lang.RunnableImplementor.n_run(Native Method)
at at mono.java.lang.RunnableImplementor.run(RunnableImplementor.java:29)
at at android.os.Handler.handleCallback(Handler.java:615)
at at android.os.Handler.dispatchMessage(Handler.java:92)
at at android.os.Looper.loop(Looper.java:137)
at at android.app.ActivityThread.main(ActivityThread.java:4745)
at at java.lang.reflect.Method.invokeNative(Native Method)
at at java.lang.reflect.Method.invoke(Method.java:511)
at at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
at at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
at at dalvik.system.NativeStart.main(Native Method)
--- End of inner exception stack trace ---
at Microsoft.Xna.Framework.Content.ContentManager.OpenStream (System.String assetName) [0x0005d] in c:\Users\Matt\Documents\Dev\Game\MonoGame_3_2\MonoGame.Framework\Content\ContentManager.cs:269
at Microsoft.Xna.Framework.Content.ContentManager.ReadAsset[Texture2D] (System.String assetName, System.Action`1 recordDisposableObject) [0x00067] in c:\Users\Matt\Documents\Dev\Game\MonoGame_3_2\MonoGame.Framework\Content\ContentManager.cs:301
--- End of inner exception stack trace ---
at at Microsoft.Xna.Framework.Content.ContentManager.ReadAsset<Microsoft.Xna.Framework.Graphics.Texture2D> (string,System.Action`1<System.IDisposable>) <0x0078f>
at at Microsoft.Xna.Framework.Content.ContentManager.Load<Microsoft.Xna.Framework.Graphics.Texture2D> (string) <0x001e3>
at MBHEngine.Behaviour.SpriteRender.LoadTexture (string) [0x00035] in c:\Users\Matt\Documents\Dev\Game\mbhwarofroses\Roses\MBHEngine\Code\Behaviour\SpriteRender.cs:525
at MBHEngine.Behaviour.SpriteRender.LoadContent (string) [0x00030] in c:\Users\Matt\Documents\Dev\Game\mbhwarofroses\Roses\MBHEngine\Code\Behaviour\SpriteRender.cs:419
at MBHEngine.Behaviour.Behaviour..ctor (MBHEngine.GameObject.GameObject,string) [0x0000f] in c:\Users\Matt\Documents\Dev\Game\mbhwarofroses\Roses\MBHEngine\Code\Behaviour\Behaviour.cs:53
at MBHEngine.Behaviour.SpriteRender..ctor (MBHEngine.GameObject.GameObject,string) [0x00000] in c:\Users\Matt\Documents\Dev\Game\mbhwarofroses\Roses\MBHEngine\Code\Behaviour\SpriteRender.cs:402
at MBHEngine.GameObject.GameObject.CreateBehaviourByName (string,string) [0x001b0] in c:\Users\Matt\Documents\Dev\Game\mbhwarofroses\Roses\MBHEngine\Code\GameObject\GameObject.cs:530
at MBHEngine.GameObject.GameObject.LoadContent (string) [0x00189] in c:\Users\Matt\Documents\Dev\Game\mbhwarofroses\Roses\MBHEngine\Code\GameObject\GameObject.cs:222
at MBHEngine.GameObject.GameObject..ctor (string) [0x0005d] in c:\Users\Matt\Documents\Dev\Game\mbhwarofroses\Roses\MBHEngine\Code\GameObject\GameObject.cs:168
at MBHEngine.GameObject.GameObjectFactory.AddTemplate (string,int) [0x0002c] in c:\Users\Matt\Documents\Dev\Game\mbhwarofroses\Roses\MBHEngine\Code\GameObject\GameObjectFactory.cs:113
at Roses.RosesGame.LoadContent () [0x00cfa] in c:\Users\Matt\Documents\Dev\Game\mbhwarofroses\Roses\Roses\RosesGame.cs:162
at Microsoft.Xna.Framework.Game.Initialize () [0x00047] in c:\Users\Matt\Documents\Dev\Game\MonoGame_3_2\MonoGame.Framework\Game.cs:577
at MBHEngine.Game.Initialize () [0x000ab] in c:\Users\Matt\Documents\Dev\Game\mbhwarofroses\Roses\MBHEngine\Code\Game\Game.cs:187
at Roses.RosesGame.Initialize () [0x00022] in c:\Users\Matt\Documents\Dev\Game\mbhwarofroses\Roses\Roses\RosesGame.cs:56
at Microsoft.Xna.Framework.Game.DoInitialize () [0x00011] in c:\Users\Matt\Documents\Dev\Game\MonoGame_3_2\MonoGame.Framework\Game.cs:707
at Microsoft.Xna.Framework.AndroidGamePlatform.BeforeUpdate (Microsoft.Xna.Framework.GameTime) [0x00008] in c:\Users\Matt\Documents\Dev\Game\MonoGame_3_2\MonoGame.Framework\Android\AndroidGamePlatform.cs:67
at Microsoft.Xna.Framework.Game.DoUpdate (Microsoft.Xna.Framework.GameTime) [0x00006] in c:\Users\Matt\Documents\Dev\Game\MonoGame_3_2\MonoGame.Framework\Game.cs:679
at Microsoft.Xna.Framework.Game.Tick () [0x001d2] in c:\Users\Matt\Documents\Dev\Game\MonoGame_3_2\MonoGame.Framework\Game.cs:528
at Microsoft.Xna.Framework.AndroidGameWindow.OnUpdateFrame (object,OpenTK.FrameEventArgs) [0x00053] in c:\Users\Matt\Documents\Dev\Game\MonoGame_3_2\MonoGame.Framework\Android\AndroidGameWindow.cs:90
at OpenTK.GameViewBase.OnUpdateFrame (OpenTK.FrameEventArgs) [0x00014] in /Users/builder/data/lanes/monodroid-mlion-monodroid-4.21-series/49a04b96/source/monodroid/src/OpenGLES/Android/GameViewBase.cs:312
at OpenTK.Platform.Android.AndroidGameView.UpdateFrameInternal (OpenTK.FrameEventArgs) [0x00013] in /Users/builder/data/lanes/monodroid-mlion-monodroid-4.21-series/49a04b96/source/monodroid/src/OpenGLES/Android/AndroidGameView.cs:338
at OpenTK.Platform.Android.AndroidGameView.RunIteration (System.Threading.CancellationToken) [0x00096] in /Users/builder/data/lanes/monodroid-mlion-monodroid-4.21-series/49a04b96/source/monodroid/src/OpenGLES/Android/AndroidGameView.cs:523
at OpenTK.Platform.Android.AndroidGameView/<StartThread>c__AnonStorey0.<>m__0 (object) [0x0000d] in /Users/builder/data/lanes/monodroid-mlion-monodroid-4.21-series/49a04b96/source/monodroid/src/OpenGLES/Android/AndroidGameView.cs:431
at Android.App.SyncContext/<Send>c__AnonStorey1.<>m__0 () [0x00000] in /Users/builder/data/lanes/monodroid-mlion-monodroid-4.21-series/49a04b96/source/monodroid/src/Mono.Android/src/Android.App/SyncContext.cs:32
at Java.Lang.Thread/RunnableImplementor.Run () [0x0000b] in /Users/builder/data/lanes/monodroid-mlion-monodroid-4.21-series/49a04b96/source/monodroid/src/Mono.Android/src/Java.Lang/Thread.cs:36
at Java.Lang.IRunnableInvoker.n_Run (intptr,intptr) [0x00009] in /Users/builder/data/lanes/monodroid-mlion-monodroid-4.21-series/49a04b96/source/monodroid/src/Mono.Android/platforms/android-15/src/generated/Java.Lang.IRunnable.cs:71
at at (wrapper dynamic-method) object.0770ba55-370c-4cc1-8319-756d9ee16385 (intptr,intptr) <IL 0x00011, 0x0001b>
Ever other texture in the game loads fine, so I assumed I did something silly with this particular texture but things got really weird as I tried to narrow it down.
First, I tried overwriting that texture file with one I know works, and it loaded fine.
I then tried just opening up the broken texture in Gimp and re-saving it (in case I had some bad settings or something), and it still failed to load.
I then tried copying and pasting the image data in that texture to a whole new file, saved that new file, and that new texture fails too! Starting to get weird…
I then made some arbitrary changes to the texture (drawing lines all over it) re-saved and now it loads! Very weird!
Just to confirm, I undid those arbitrary changes, re-saved the texture again, and it fails to load again.
I then made some really minor changes to the texture (adding a single red pixel) and that still fails to load. So it seems to require a “significant” (what ever that is) change to fix the loading issue.
I have put the two versions of the PNG (and resulting XNB) here hoping that someone might be able to tell me what would cause one to fail to load and the other work!