Make the GL3 renderer's R_SortDrawSurfaces() emulate a stable sort

The vanilla renderer uses a stable sorting algorithm for R_SortDrawSurfaces
This has the nice property of preserving the front to back bsp traversal order
Fix some potential buffer overflows