mirror of
https://github.com/yquake2/yquake2remaster.git
synced 2024-11-26 22:40:50 +00:00
If CM_LeafCluster() returned -1, don't use that as array index, fix #894
It seems to return -1 if the leaf is in the void; sometimes it also seems to happen when you're just close to a wall, maybe due to (mis)prediction. ASan complains about this, but in practice it probably can't cause issues, as the byte left to the mask array (from CM_ClusterPVS() or CM_ClusterPHS()) will either belong to another global variable or padding between them. Fixed it anyway.
This commit is contained in:
parent
d29e551773
commit
4d6bdcc853
2 changed files with 11 additions and 3 deletions
|
@ -293,7 +293,10 @@ PF_inPVS(vec3_t p1, vec3_t p2)
|
|||
cluster = CM_LeafCluster(leafnum);
|
||||
area2 = CM_LeafArea(leafnum);
|
||||
|
||||
if (mask && (!(mask[cluster >> 3] & (1 << (cluster & 7)))))
|
||||
// cluster -1 means "not in a visible leaf" or something like that (void?)
|
||||
// so p1 and p2 probably don't "see" each other.
|
||||
// either way, we must avoid using a negative index into mask[]!
|
||||
if (cluster < 0 || (!(mask[cluster >> 3] & (1 << (cluster & 7)))))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
@ -326,7 +329,10 @@ PF_inPHS(vec3_t p1, vec3_t p2)
|
|||
cluster = CM_LeafCluster(leafnum);
|
||||
area2 = CM_LeafArea(leafnum);
|
||||
|
||||
if (mask && (!(mask[cluster >> 3] & (1 << (cluster & 7)))))
|
||||
// cluster -1 means "not in a visible leaf" or something like that (void?)
|
||||
// so p1 and p2 probably don't "hear" each other.
|
||||
// either way, we must avoid using a negative index into mask[]!
|
||||
if (cluster < 0 || (!(mask[cluster >> 3] & (1 << (cluster & 7)))))
|
||||
{
|
||||
return false; /* more than one bounce away */
|
||||
}
|
||||
|
|
|
@ -227,7 +227,9 @@ SV_Multicast(vec3_t origin, multicast_t to)
|
|||
continue;
|
||||
}
|
||||
|
||||
if (!(mask[cluster >> 3] & (1 << (cluster & 7))))
|
||||
// cluster can be -1 if we're in the void (or sometime just at a wall)
|
||||
// and using a negative index into mask[] would be invalid
|
||||
if (cluster < 0 || !(mask[cluster >> 3] & (1 << (cluster & 7))))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue