FWGS / xash3d

DEPRECATED in favor of https://github.com/FWGS/xash3d-fwgs. Only bugfixes are accepted.
https://xash.su
GNU General Public License v3.0
549 stars 107 forks source link

VBO index buffer length calculated incorrectly, can overflow #406

Closed noodlecollie closed 5 years ago

noodlecollie commented 5 years ago

I only found this out because of peculiarities in the Nightfire BSP format I'm attempting to load. I'm not sure whether it occurs with Half Life BSPs (at least, I haven't been able to reproduce it yet), but nonetheless it should probably be fixed. I'll create a pull request today when I'm not in a rush.

Currently, vbotexture_t::len is used to accumulate the number of vertices from polygons that use this VBO. The length of thevbotexture_t::indexarray is then calculated as sizeof( unsigned short ) * 6 * len. However, when indices are added to the index array, there are 3(n-2) indices added for a face with n vertices (see R_AddSurfToVBO()).

Occasionally R_AddSurfToVBO() has overflowed the array for me. It would be better to keep a more accurate count when incrementing len - I have tested this locally and it seems to solve the overflow problem for me.

a1batross commented 5 years ago

@mittorn

a1batross commented 5 years ago

Fixed in PR.