Added condition for when rounding up of texture map leads to array index overflow
Merge with Mathias branch
Merge with Akaash branch