From 46ce65f8eca943f04c7a07df739e5d032fec1835 Mon Sep 17 00:00:00 2001 From: XProger Date: Mon, 26 Feb 2018 04:06:46 +0300 Subject: [PATCH] #23 fix PSX RNC images loader --- src/platform/web/build.bat | 2 +- src/texture.h | 3 ++- src/utils.h | 1 + 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/platform/web/build.bat b/src/platform/web/build.bat index c4b03c7..a8acb87 100644 --- a/src/platform/web/build.bat +++ b/src/platform/web/build.bat @@ -4,5 +4,5 @@ set SRC=main.cpp ../../libs/stb_vorbis/stb_vorbis.c ../../libs/tinf/tinflate.c set PROJ=OpenLara set FLAGS=-O3 -Wno-deprecated-register --llvm-opts 2 -fmax-type-align=2 -std=c++11 -s ALLOW_MEMORY_GROWTH=1 -Wall -I../../ echo. -call em++ %SRC% %FLAGS% -o %PROJ%.js --preload-file ./level/1/TITLE.PSX --preload-file ./level/1/AMERTIT.PNG --preload-file ./audio/1/dummy --preload-file ./audio/2/dummy --preload-file ./audio/3/dummy --preload-file ./level/2/dummy --preload-file ./level/3/dummy +call em++ %SRC% %FLAGS% -o %PROJ%.js --preload-file ./level/1/TITLE.PSX --preload-file ./audio/1/dummy --preload-file ./audio/2/dummy --preload-file ./audio/3/dummy --preload-file ./level/2/dummy --preload-file ./level/3/dummy gzip.exe -9 -f %PROJ%.data %PROJ%.js %PROJ%.js.mem \ No newline at end of file diff --git a/src/texture.h b/src/texture.h index 08ba9e5..c80612e 100644 --- a/src/texture.h +++ b/src/texture.h @@ -654,12 +654,13 @@ struct Texture { BitStream bs(cdata, csize); uint8 *dst = data; + uint8 *end = data + size; uint32 length = 0; uint16 offset = 0; bs.readBits(2); - while (bs.data < bs.end || bs.index > 0) { + while (bs.data < bs.end && dst < end) { if (!bs.readBit()) { *dst++ = bs.readByte(); } else { diff --git a/src/utils.h b/src/utils.h index 4850c2e..c438268 100644 --- a/src/utils.h +++ b/src/utils.h @@ -1320,6 +1320,7 @@ struct BitStream { } uint8 readByte() { + ASSERT(data < end); return *data++; } };