Added RAII for graphics engine