mirror of
https://github.com/mkxp-z/mkxp-z.git
synced 2025-08-23 15:23:44 +02:00
Avoid out-of-bounds array access in tilemap shader
This breaks the shader on my Android device. When `atIndex` is out of bounds, `atFrames[atIndex]` evaluates to 0 and so `aniIndex / atFrames[atIndex]` results in division by 0. All of the tiles where this division by 0 occurs are blank on my Android device. That probably means the shader pipeline halts when division by 0 occurs.
This commit is contained in:
parent
cb302d2475
commit
6290703847
1 changed files with 8 additions and 6 deletions
|
@ -27,12 +27,14 @@ void main()
|
|||
vec2 tex = texCoord;
|
||||
lowp int atIndex = int(tex.y / autotileH);
|
||||
|
||||
lowp int pred = int(tex.x <= atAreaW && tex.y <= atAreaH);
|
||||
lowp int frame = int(aniIndex - atFrames[atIndex] * (aniIndex / atFrames[atIndex]));
|
||||
lowp int row = frame / 8;
|
||||
lowp int col = frame - 8 * row;
|
||||
tex.x += atAniOffsetX * float(col * pred);
|
||||
tex.y += atAniOffsetY * float(row * pred);
|
||||
if (atIndex < nAutotiles) {
|
||||
lowp int pred = int(tex.x <= atAreaW && tex.y <= atAreaH);
|
||||
lowp int frame = int(aniIndex - atFrames[atIndex] * (aniIndex / atFrames[atIndex]));
|
||||
lowp int row = frame / 8;
|
||||
lowp int col = frame - 8 * row;
|
||||
tex.x += atAniOffsetX * float(col * pred);
|
||||
tex.y += atAniOffsetY * float(row * pred);
|
||||
}
|
||||
|
||||
gl_Position = projMat * vec4(position + translation, 0, 1);
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue