Fix texture rendering and memory management