Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Fix edge case where PixmapPacker eats all memory in infinite recursion #191

Merged
merged 1 commit into from

2 participants

@ttencate

Please check if I got this right; there is no test for it, and I can't seem to use my own libgdx build in my game right now.

@badlogic
Owner

Wow, never seen this. Wonder why your patch would fix an infinite loop, but it sure looks nicer :)

@ttencate

The "+ borderPixels" is on the wrong side of the ">=" sign. So if the image almost, or exactly, fits inside the page, but wouldn't fit if you include the border, no exception is thrown. But node will always be null since it doesn't fit, so a new page is created (eating an MB of ram for 512x512 pages) and the whole thing recursively starts over again :)

@badlogic
Owner

Wow, i thought i merged this. Sorry, merged now, thanks!

@badlogic badlogic merged commit 241858a into libgdx:master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
Showing with 3 additions and 3 deletions.
  1. +3 −3 gdx/src/com/badlogic/gdx/graphics/g2d/PixmapPacker.java
View
6 gdx/src/com/badlogic/gdx/graphics/g2d/PixmapPacker.java
@@ -158,10 +158,10 @@ public synchronized Rectangle pack (String name, Pixmap image) {
int borderPixels = padding + (duplicateBorder ? 1 : 0);
borderPixels <<= 1;
- if (image.getWidth() >= pageWidth + borderPixels || image.getHeight() >= pageHeight + borderPixels)
- throw new GdxRuntimeException("page size for '" + name + "' to small");
-
Rectangle rect = new Rectangle(0, 0, image.getWidth() + borderPixels, image.getHeight() + borderPixels);
+ if (rect.getWidth() > pageWidth || rect.getHeight() > pageHeight)
+ throw new GdxRuntimeException("page size for '" + name + "' to small");
+
Node node = insert(currPage.root, rect);
if (node == null) {
Something went wrong with that request. Please try again.