LibGDX - application crash when calling TiledMapRenderer.render ()

@Override public void render(float delta) { Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT); camera.update(); sprite.setProjectionMatrix(camera.combined); mLevel.getTiledMapRenderer().getProjectionMatrix().set(camera.combined); Vector3 tmp = new Vector3(); tmp.set(0, 0, 0); camera.unproject(tmp); mLevel.getTiledMapRenderer().render(tmp.x, tmp.y, camera.viewportWidth, camera.viewportHeight); sprite.begin(); ... sprite.end(); } 

Here is what I get when starting the desktop version:

 Exception in thread "LWJGL Application" java.lang.IllegalArgumentException: Number of remaining buffer elements is 0, must be at least 1. Because at most 1 elements can be returned, a buffer with at least 1 elements is required, regardless of actual returned element count at org.lwjgl.BufferChecks.throwBufferSizeException(BufferChecks.java:162) at org.lwjgl.BufferChecks.checkBufferSize(BufferChecks.java:189) at org.lwjgl.BufferChecks.checkBuffer(BufferChecks.java:230) at org.lwjgl.opengl.GL15.glBufferData(GL15.java:141) at com.badlogic.gdx.backends.lwjgl.LwjglGL20.glBufferData(LwjglGL20.java:93) at com.badlogic.gdx.graphics.glutils.VertexBufferObject.bind(VertexBufferObject.java:208) at com.badlogic.gdx.graphics.Mesh.bind(Mesh.java:268) at com.badlogic.gdx.graphics.g2d.SpriteCache.begin(SpriteCache.java:868) at com.badlogic.gdx.graphics.g2d.tiled.TileMapRenderer.render(TileMapRenderer.java:336) at com.badlogic.gdx.graphics.g2d.tiled.TileMapRenderer.render(TileMapRenderer.java:286) at com.crunsh.libgdx.screens.GameScreen.render(GameScreen.java:102) at com.badlogic.gdx.Game.render(Game.java:46) at com.badlogic.gdx.backends.lwjgl.LwjglApplication.mainLoop(LwjglApplication.java:202) at com.badlogic.gdx.backends.lwjgl.LwjglApplication$1.run(LwjglApplication.java:131) 

I tried both the tuton and this , and I get the same error in the same line mLevel.getTiledMapRenderer().render(tmp.x, tmp.y, camera.viewportWidth, camera.viewportHeight); , camera.viewportWidth, camera.viewportHeight).; .

EDIT: I just noticed that the data in my .tmx file was automatically encoded in the Tiled Map Editor, so I just deactivated it, but still get the same error.
If I copy / paste this project (I mean the whole project, not just the render () method), but when I try to load my own map in my own project, it just crashes ...

So, after that, I decided to simplify my render() method by simply following the link I gave earlier and using the TiledMapHelper class that the author provides, so now there is my render() method:

 mHelper.getCamera().update(); mHelper.render(); 

More crashiiiiiiiiiiiiiiiingg .....
If someone can provide some help, it will be very grateful, because I'm really going crazy!

+6
source share
1 answer

I found the cause of the error:
1) all tiles in my "packfile" had -1 as their index
2) all the tiles in my "packfile" had the same name as the original tile file name, but not the same name as the .png file containing all the packed tiles.

Currently my screen is black, so I think that no tiles are drawn (probably because I gave random indices for the fragments in the packfile - fixed, see the end of the message ), but no exceptions were selected and that is the point.

These errors are related to the program that I used to pack the tiles, which were supposed to make me buy LOL time. Therefore, I will try to use different options or use something else.
If you want to know that the program was "TexturePacker GUI" v3.1.0.

If you know which options I should / should not use to avoid errors, please let me know.

EDIT: Found a useful and working tool for packing tiles, here it is: http://freigabe.philweb.de/bubblr/texturepacker_edited.jar (the link is dead, use => http://bit.ly/1a831nv or another tool instead packaging => http://bit.ly/1aLgAFt )

To use it, open cmd and navigate to the directory where you downloaded the .jar file, and then:

 //You should create, in the same directory of the .jar file, two additionnal folders //Call the first folder 'input' and put in all your tiles (rename them "level_1.png", "level_..") //Call the 2nd folder 'output' and leave it empty //Then just type in the command prompt : java -jar nameOfDownloadedJarFile.jar input output level //Then rename the "input1.png" into "level.png", and "level.pack" into "level packfile" //Open "level packfile" with notepad and change "input1.png" into "level.png" //Then draw your map using "level.png" in TiledMapEditor //Then just follow dpk' tutorial for rendering the map and it should work 

Here is the dpk tutorial that I talked about, just follow from here: http://dpk.net/2011/05/01/libgdx-box2d-tiled-maps-full-working-example-part-1/#p4

If the application does not work, but the screen is black, just increase the width and height of the viewport.

Happy display :)!

+8
source

Source: https://habr.com/ru/post/921752/


All Articles