Add protections against potential negative values (may produce a crash with OpenGL)