This patch fixes some ordering issues in HWR_CreateDrawNodes. It also makes it faster by replacing the O(n^2) bubble sort algorithm with O(n \log n) quick sort.
O(n^2)
O(n \log n)
Comparison images:
Performance comparison: