Make SubRange type generic

Fix DX pointer crash during exit
Use signed int instead of int for portability