Skip to content

Commit 7ce8e5d

Browse files
committed
Fix sprite issue
[HSP3Dish] 標準スプライト表示時にキャラクターNo.が正しくない時に落ちる不具合を修正
1 parent 1a02bd4 commit 7ce8e5d

File tree

2 files changed

+29
-20
lines changed

2 files changed

+29
-20
lines changed

src/hsp3dish/essprite.cpp

Lines changed: 27 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -585,6 +585,8 @@ int essprite::put(int xx, int yy, int chrno, int tpflag, int zoomx, int zoomy, i
585585
x = xx; y = yy;
586586
if ((chrno < 0) || (chrno >= chrkaz)) return -1;
587587
chr = &mem_chr[chrno];
588+
if (chr == NULL) return -2;
589+
if (chr->wid <= 0) return -2;
588590
nx = chr->bsx; ny = chr->bsy;
589591
ix = chr->bx; iy = chr->by;
590592
ofsx = chr->putofsx;
@@ -603,20 +605,20 @@ int essprite::put(int xx, int yy, int chrno, int tpflag, int zoomx, int zoomy, i
603605

604606
x += ofsx; y += ofsy;
605607
if (sprite_clip) {
606-
if ((x + vx) <= 0) return -1;
607-
if ((x - vx) > main_sx) return -1;
608-
if ((y + vy) <= 0) return -1;
609-
if ((y - vy) > main_sy) return -1;
608+
if ((x + vx) <= 0) return 1;
609+
if ((x - vx) > main_sx) return 1;
610+
if ((y + vy) <= 0) return 1;
611+
if ((y - vy) > main_sy) return 1;
610612
}
611613
}
612614
else {
613615
vx = nx; vy = ny;
614616
x += ofsx; y += ofsy;
615617
if (sprite_clip) {
616-
if ((x + vx) <= 0) return -1;
617-
if (x > main_sx) return -1;
618-
if ((y + vy) <= 0) return -1;
619-
if (y > main_sy) return -1;
618+
if ((x + vx) <= 0) return 1;
619+
if (x > main_sx) return 1;
620+
if ((y + vy) <= 0) return 1;
621+
if (y > main_sy) return 1;
620622
}
621623
}
622624

@@ -732,6 +734,8 @@ int essprite::put2(int xx, int yy, int chrno, int tpflag, int zoomx, int zoomy,
732734
x = xx; y = yy;
733735
if ((chrno < 0) || (chrno >= chrkaz)) return -1;
734736
chr = &mem_chr[chrno];
737+
if (chr == NULL) return -2;
738+
if (chr->wid <= 0) return -2;
735739
nx = chr->bsx; ny = chr->bsy;
736740
ix = chr->bx; iy = chr->by;
737741
ofsx = chr->putofsx;
@@ -747,20 +751,20 @@ int essprite::put2(int xx, int yy, int chrno, int tpflag, int zoomx, int zoomy,
747751

748752
x += ofsx; y += ofsy;
749753
if (sprite_clip) {
750-
if ((x + vx) <= 0) return -1;
751-
if ((x - vx) > main_sx) return -1;
752-
if ((y + vy) <= 0) return -1;
753-
if ((y - vy) > main_sy) return -1;
754+
if ((x + vx) <= 0) return 1;
755+
if ((x - vx) > main_sx) return 1;
756+
if ((y + vy) <= 0) return 1;
757+
if ((y - vy) > main_sy) return 1;
754758
}
755759
}
756760
else {
757761
vx = nx; vy = ny;
758762
x += ofsx; y += ofsy;
759763
if (sprite_clip) {
760-
if ((x + vx) <= 0) return -1;
761-
if (x > main_sx) return -1;
762-
if ((y + vy) <= 0) return -1;
763-
if (y > main_sy) return -1;
764+
if ((x + vx) <= 0) return 1;
765+
if (x > main_sx) return 1;
766+
if ((y + vy) <= 0) return 1;
767+
if (y > main_sy) return 1;
764768
}
765769
}
766770

@@ -1785,6 +1789,7 @@ int essprite::drawSubPut(SPOBJ *sp, int mode)
17851789
{
17861790
// 1 sprite draw (on sp)
17871791
//
1792+
int st;
17881793
int res = 0;
17891794
int fl,x,y,xx,yy,blink;
17901795
int next;
@@ -1838,10 +1843,14 @@ int essprite::drawSubPut(SPOBJ *sp, int mode)
18381843
}
18391844
}
18401845
if (sprite_newfunc) {
1841-
put2(x + ofsx, y + ofsy, chr, sp->tpflag, sp->zoomx, sp->zoomy, sp->rotz, sp->mulcolor, mode);
1846+
st = put2(x + ofsx, y + ofsy, chr, sp->tpflag, sp->zoomx, sp->zoomy, sp->rotz, sp->mulcolor, mode);
18421847
}
18431848
else {
1844-
put(x + ofsx, y + ofsy, chr, sp->tpflag, sp->zoomx, sp->zoomy, sp->rotz, sp->mulcolor, mode);
1849+
st = put(x + ofsx, y + ofsy, chr, sp->tpflag, sp->zoomx, sp->zoomy, sp->rotz, sp->mulcolor, mode);
1850+
}
1851+
if (st < 0) {
1852+
Alertf("Invalid sprite CHR#%d (%d)", chr, st);
1853+
throw HSPERR_ILLEGAL_FUNCTION;
18451854
}
18461855
res++;
18471856
}

src/hsp3dish/hsp3gr_dish.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3601,10 +3601,10 @@ static int cmdfunc_extcmd( int cmd )
36013601
p7 = code_getdi(0);
36023602
if (sprite->sprite_enable) {
36033603
if (sprite->sprite_newfunc) {
3604-
sprite->put2(p1, p2, p3, p4, p5, p6, p7, bmscr->mulcolor);
3604+
ctx->stat = sprite->put2(p1, p2, p3, p4, p5, p6, p7, bmscr->mulcolor);
36053605
}
36063606
else {
3607-
sprite->put(p1, p2, p3, p4, p5, p6, p7, bmscr->mulcolor);
3607+
ctx->stat = sprite->put(p1, p2, p3, p4, p5, p6, p7, bmscr->mulcolor);
36083608
}
36093609
} else throw HSPERR_UNSUPPORTED_FUNCTION;
36103610
break;

0 commit comments

Comments
 (0)