Question

I'm having the following exception when running on iOS a code that works fine on Java:

Unhandled Exception:
java.lang.IllegalStateException: Attempted to generate texture before GL was initialized. 
You cannot create and render SurfaceLayer in Game.init() on iOS.
2014-02-13 02:12:18.821 ProjectMainJava[19077:21e03] Unhandled managed exception: Attempted to generate texture before GL was initialized. You cannot create and render SurfaceLayer in Game.init() on iOS. (java.lang.IllegalStateException)
  at playn.ios.IOSGLContext.createTexture (Boolean repeatX, Boolean repeatY, Boolean mipmaps) [0x001e7] in IOSGLContext.java:165 
  at playn.ios.IOSGLContext.createTexture (Int32 width, Int32 height, Boolean repeatX, Boolean repeatY, Boolean mm) [0x0000a] in IOSGLContext.java:170 
  at playn.core.gl.SurfaceGL.createTexture () [0x00001] in SurfaceGL.java:63 
  at playn.core.gl.SurfaceGL..ctor (playn.core.gl.GLContext ctx, Single width, Single height) [0x00045] in SurfaceGL.java:34 
  at playn.core.gl.GraphicsGL.createSurfaceGL (Single width, Single height) [0x00001] in GraphicsGL.java:88 
  at playn.core.gl.GraphicsGL.createSurface (Single width, Single height) [0x00001] in GraphicsGL.java:84 
  at ma.company.core.ProjectMainJava.init () [0x0006d] in ProjectMainJava.java:41 
  at playn.ios.IOSPlatform.run (Game game) [0x00009] in IOSPlatform.java:353 
  at playn.core.PlayN.run (Game game) [0x00001] in PlayN.java:47 
  at ma.company.AppDelegate.FinishedLaunching (MonoTouch.UIKit.UIApplication app, MonoTouch.Foundation.NSDictionary options) [0x00000] in <filename unknown>:0 
  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 ma.company.Application.Main (System.String[] args) [0x00000] in <filename unknown>:0 

mono-rt: Stacktrace:

I'm not using any SurfaceLayer in my code (as it's been deprecated since the version 1.7) though.

My code is :

@Override
public void init() {

    GroupLayer g = graphics().createGroupLayer();

    graphics().rootLayer().add(g);

    PlayN.log().error("BEFORE");
    SurfaceImage backgroundTopImage = graphics().createSurface(
            graphics().width(), graphics().height() / 2);
    PlayN.log().error("AFTER");

    backgroundTopImage.surface().setFillColor(SKY_COLOR);
    backgroundTopImage.surface().fillRect(0, 0, backgroundTopImage.width(),
            backgroundTopImage.height());

    ImageLayer backgroundTop = graphics().createImageLayer(
            backgroundTopImage);
    g.addAt(backgroundTop, 0, 0);

}

I can see the "BEFORE" log but not the After.

PlayN version 1.7.

Was it helpful?

Solution

The issue has been adressed here:

https://groups.google.com/forum/#!topic/playn/wnyWiQRaX4Q

And the solution is:

final Image bi = PlayN.assets().getImage("images/BG.png");
AssetWatcher assetWatcher = new AssetWatcher(
    new AssetWatcher.Listener() {

        @Override
        public void done() {
            //Create all the layers here..
        }

        @Override
        public void error(Throwable e) {
            PlayN.log().debug("Interface game menu load error");
        });

    assetWatcher.add(bi);
    assetWatcher.start();
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top