libgdx icon indicating copy to clipboard operation
libgdx copied to clipboard

GWT build issue with Pixmap.createFromFrameBuffer

Open galloj opened this issue 3 years ago • 2 comments

Issue details

It isn't possible to compile following code on GWT (required for taking screenshots):

Pixmap pixmap = Pixmap.createFromFrameBuffer(0, 0, Gdx.graphics.getBackBufferWidth(), Gdx.graphics.getBackBufferHeight());
ByteBuffer pixels = pixmap.getPixels();

It gives following error when compiling: Type mismatch: cannot convert from Buffer to ByteBuffer

And seems to be caused by this line, with IDE showing the line as syntax error.

It shows also this and this line as syntax error with message Cannot resolve symbol 'pixmap', but I have no idea why and it isn't causing any problems for me (most likely because I am not calling those functions).

Version of libGDX and/or relevant dependencies

1.11.0

Please select the affected platforms

  • [ ] Android
  • [ ] iOS
  • [x] HTML/GWT
  • [ ] Windows
  • [ ] Linux
  • [ ] macOS

galloj avatar Jun 18 '22 17:06 galloj

The issue is actually with getPixels(), but it's... complicated. On all platforms except GWT, getPixels() returns a ByteBuffer. On GWT, it returns a Buffer, backed by an IntBuffer. There's some reason for this relating to how WebGL works, but I don't know the specifics. GWT has to use different sources for Pixmap and its backing data, because desktop and Android (plus more, probably) can use C++ code with JNI, while GWT cannot, and so has to use JS code to implement Pixmap operations. You can see the relevant sources used by GWT here. Ideally, we would have some way of converting the IntBuffer of pixels to a ByteBuffer like all other platforms use, but it's been a challenge so far.

tommyettinger avatar Jun 18 '22 22:06 tommyettinger

Same issue. I'm using GifDecoder.

minecraft8997 avatar Jul 05 '22 14:07 minecraft8997