Fix tex memory allocation
Fix memory issues