fix memory corruption in texture loading
TODO: make sure this behavior is ok