Skip to content

Commit

Permalink
Fix .pti compression assuming data length included the header, which …
Browse files Browse the repository at this point in the history
…it doesn't
  • Loading branch information
jacob1 committed Mar 23, 2024
1 parent b073c1c commit eb696b3
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/PowderToyRenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ int main(int argc, char *argv[])
}
else
{
ren->clearScreen();
int w = Graphics::TextSize("Save file invalid").X + 15, x = (XRES-w)/2, y = (YRES-24)/2;
ren->DrawRect(RectSized(Vec2{ x, y }, Vec2{ w, 24 }), 0xC0C0C0_rgb);
ren->BlendText({ x+8, y+8 }, "Save file invalid", 0xC0C0F0_rgb .WithAlpha(255));
Expand Down
4 changes: 2 additions & 2 deletions src/graphics/Graphics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ std::unique_ptr<std::vector<char>> Graphics::ptif_pack(PlaneAdapter<std::vector<
unsigned char *red_chan = (unsigned char*)calloc(1, w*h);
unsigned char *green_chan = (unsigned char*)calloc(1, w*h);
unsigned char *blue_chan = (unsigned char*)calloc(1, w*h);
unsigned char *data = (unsigned char*)malloc(((w*h)*3)+8);
unsigned char *data = (unsigned char*)malloc(((w*h)*3));

for (int cx = 0; cx < w; cx++)
{
Expand Down Expand Up @@ -213,7 +213,7 @@ std::unique_ptr<std::vector<char>> Graphics::ptif_pack(PlaneAdapter<std::vector<
header[7] = h>>8;

std::vector<char> result;
if (BZ2WCompress(result, (char *)data, ((w*h)*3)+8, ((w*h)*3)+8) != BZ2WCompressOk)
if (BZ2WCompress(result, (char *)data, (w*h)*3, (w*h)*3) != BZ2WCompressOk)
{
free(data);
delete[] header;
Expand Down

0 comments on commit eb696b3

Please sign in to comment.