Skip to content

Commit

Permalink
Pixmap crash fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Anuken committed Jun 13, 2024
1 parent 732de1b commit 98900b2
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 4 deletions.
13 changes: 12 additions & 1 deletion arc-core/src/arc/graphics/Pixmap.java
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,7 @@ public void draw(Pixmap pixmap, int srcx, int srcy, int srcWidth, int srcHeight,
setRaw(dx, dy, blend(pixmap.getRaw(sx, sy), getRaw(dx, dy)));
}
}
}else{
}else if(this.pixels != pixmap.pixels){ //make sure the buffers are different to prevent a crash
ByteBuffer pixels = this.pixels, otherPixels = pixmap.pixels;
int
startY = Math.max(dsty, 0),
Expand Down Expand Up @@ -427,6 +427,17 @@ public void draw(Pixmap pixmap, int srcx, int srcy, int srcWidth, int srcHeight,
pixels.position(0);
otherPixels.position(0);
otherPixels.limit(otherPixels.capacity());
}else{ //drawing a pixmap onto itself is not a good idea, but it's better than crashing
for(; sy < srcy + srcHeight; sy++, dy++){
if(sy < 0 || dy < 0) continue;
if(sy >= oheight || dy >= height) break;

for(sx = srcx, dx = dstx; sx < srcx + srcWidth; sx++, dx++){
if(sx < 0 || dx < 0) continue;
if(sx >= owidth || dx >= width) break;
setRaw(dx, dy, pixmap.getRaw(sx, sy));
}
}
}
}else{
if(filtering){
Expand Down
10 changes: 7 additions & 3 deletions arc-core/src/arc/util/Strings.java
Original file line number Diff line number Diff line change
Expand Up @@ -205,9 +205,13 @@ public static int count(String str, String substring){

/** Replaces non-safe filename characters with '_'. Handles reserved window file names. */
public static String sanitizeFilename(String str){
//turn things like con.msch -> acon.msch, which is no longer reserved
if(reservedFilenamePattern.matcher(str).matches()){
return "a" + str;
if(str.equals(".")){
return "_";
}else if(str.equals("..")){
return "__";
}else if(reservedFilenamePattern.matcher(str).matches()){
//turn things like con.msch -> _con.msch, which is no longer reserved
str = "_" + str;
}
return filenamePattern.matcher(str).replaceAll("_");
}
Expand Down
12 changes: 12 additions & 0 deletions arc-core/test/StringsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,18 @@ public void testDoubleParse(){
.each(StringsTest::checkDouble);
}

@Test
public void testSanitizeFilename(){
assertEquals(Strings.sanitizeFilename("test"), "test");
assertEquals(Strings.sanitizeFilename("test.txt"), "test.txt");
assertEquals(Strings.sanitizeFilename("test/test"), "test_test");
assertEquals(Strings.sanitizeFilename("CON"), "_CON");
assertEquals(Strings.sanitizeFilename("CON.a/test"), "_CON.a_test");
assertEquals(Strings.sanitizeFilename("."), "_");
assertEquals(Strings.sanitizeFilename(".."), "__");
assertEquals(Strings.sanitizeFilename("..txt"), "..txt");
}

static void checkDouble(String value){
assertEquals(Double.parseDouble(value), Strings.parseDouble(value, 999999), 0.00001);
}
Expand Down

0 comments on commit 98900b2

Please sign in to comment.