From 990974671819ddf95224d657646ea691cbb9fce8 Mon Sep 17 00:00:00 2001 From: Hannu Hanhi Date: Sun, 12 Jul 2020 21:50:00 +0300 Subject: [PATCH 1/2] Fix crash by handling precip mobjs correctly in ogl sprite sorting --- src/hardware/hw_glob.h | 2 +- src/hardware/hw_main.c | 13 +++++++------ 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/src/hardware/hw_glob.h b/src/hardware/hw_glob.h index 8efa5a1f8..51b45178d 100644 --- a/src/hardware/hw_glob.h +++ b/src/hardware/hw_glob.h @@ -68,7 +68,7 @@ typedef struct gr_vissprite_s GLPatch_t *gpatch; boolean flip; UINT8 translucency; //alpha level 0-255 - mobj_t *mobj; + mobj_t *mobj; // NOTE: This is a precipmobj_t if precip is true !!! Watch out. boolean precip; // Tails 08-25-2002 boolean vflip; //Hurdler: 25/04/2000: now support colormap in hardware mode diff --git a/src/hardware/hw_main.c b/src/hardware/hw_main.c index bde19dca0..f89e0d019 100644 --- a/src/hardware/hw_main.c +++ b/src/hardware/hw_main.c @@ -4256,8 +4256,9 @@ static int CompareVisSprites(const void *p1, const void *p2) int transparency1; int transparency2; - int linkdraw1 = (spr1->mobj->flags2 & MF2_LINKDRAW) && spr1->mobj->tracer; - int linkdraw2 = (spr2->mobj->flags2 & MF2_LINKDRAW) && spr2->mobj->tracer; + // check for precip first, because then sprX->mobj is actually a precipmobj_t and does not have flags2 or tracer + int linkdraw1 = !spr1->precip && (spr1->mobj->flags2 & MF2_LINKDRAW) && spr1->mobj->tracer; + int linkdraw2 = !spr2->precip && (spr2->mobj->flags2 & MF2_LINKDRAW) && spr2->mobj->tracer; // ^ is the XOR operation // if comparing a linkdraw and non-linkdraw sprite or 2 linkdraw sprites with different tracers, then use @@ -4272,7 +4273,7 @@ static int CompareVisSprites(const void *p1, const void *p2) else { tz1 = spr1->tz; - transparency1 = (spr1->mobj->flags2 & MF2_SHADOW) || (spr1->mobj->frame & FF_TRANSMASK); + transparency1 = !spr1->precip && ((spr1->mobj->flags2 & MF2_SHADOW) || (spr1->mobj->frame & FF_TRANSMASK)); } if (linkdraw2) { @@ -4282,15 +4283,15 @@ static int CompareVisSprites(const void *p1, const void *p2) else { tz2 = spr2->tz; - transparency2 = (spr2->mobj->flags2 & MF2_SHADOW) || (spr2->mobj->frame & FF_TRANSMASK); + transparency2 = !spr2->precip && ((spr2->mobj->flags2 & MF2_SHADOW) || (spr2->mobj->frame & FF_TRANSMASK)); } } else { tz1 = spr1->tz; - transparency1 = (spr1->mobj->flags2 & MF2_SHADOW) || (spr1->mobj->frame & FF_TRANSMASK); + transparency1 = !spr1->precip && ((spr1->mobj->flags2 & MF2_SHADOW) || (spr1->mobj->frame & FF_TRANSMASK)); tz2 = spr2->tz; - transparency2 = (spr2->mobj->flags2 & MF2_SHADOW) || (spr2->mobj->frame & FF_TRANSMASK); + transparency2 = !spr2->precip && ((spr2->mobj->flags2 & MF2_SHADOW) || (spr2->mobj->frame & FF_TRANSMASK)); } // first compare transparency flags, then compare tz, then compare dispoffset From 3a488c243f96869cec0b7f9fa4a88466b92ea43f Mon Sep 17 00:00:00 2001 From: Hannu Hanhi Date: Sun, 12 Jul 2020 22:23:15 +0300 Subject: [PATCH 2/2] Fix translucency comparison from previous commit --- src/hardware/hw_main.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/hardware/hw_main.c b/src/hardware/hw_main.c index f89e0d019..670683337 100644 --- a/src/hardware/hw_main.c +++ b/src/hardware/hw_main.c @@ -4273,7 +4273,7 @@ static int CompareVisSprites(const void *p1, const void *p2) else { tz1 = spr1->tz; - transparency1 = !spr1->precip && ((spr1->mobj->flags2 & MF2_SHADOW) || (spr1->mobj->frame & FF_TRANSMASK)); + transparency1 = (!spr1->precip && (spr1->mobj->flags2 & MF2_SHADOW)) || (spr1->mobj->frame & FF_TRANSMASK); } if (linkdraw2) { @@ -4283,15 +4283,15 @@ static int CompareVisSprites(const void *p1, const void *p2) else { tz2 = spr2->tz; - transparency2 = !spr2->precip && ((spr2->mobj->flags2 & MF2_SHADOW) || (spr2->mobj->frame & FF_TRANSMASK)); + transparency2 = (!spr2->precip && (spr2->mobj->flags2 & MF2_SHADOW)) || (spr2->mobj->frame & FF_TRANSMASK); } } else { tz1 = spr1->tz; - transparency1 = !spr1->precip && ((spr1->mobj->flags2 & MF2_SHADOW) || (spr1->mobj->frame & FF_TRANSMASK)); + transparency1 = (!spr1->precip && (spr1->mobj->flags2 & MF2_SHADOW)) || (spr1->mobj->frame & FF_TRANSMASK); tz2 = spr2->tz; - transparency2 = !spr2->precip && ((spr2->mobj->flags2 & MF2_SHADOW) || (spr2->mobj->frame & FF_TRANSMASK)); + transparency2 = (!spr2->precip && (spr2->mobj->flags2 & MF2_SHADOW)) || (spr2->mobj->frame & FF_TRANSMASK); } // first compare transparency flags, then compare tz, then compare dispoffset