don't destroy gl resources if initialization failed

This commit is contained in:
Anthony Pesch 2015-09-27 03:23:45 -07:00
parent 2cb63d3851
commit 334a76fea5
2 changed files with 8 additions and 7 deletions

View File

@ -59,9 +59,13 @@ static GLenum blend_funcs[] = {
GL_DST_COLOR, GL_ONE_MINUS_DST_COLOR};
GLBackend::GLBackend(GLContext &ctx)
: ctx_(ctx), textures_{0}, num_verts2d_(0), num_surfs2d_(0) {}
: ctx_(ctx), initialized_(false), textures_{0}, num_verts2d_(0), num_surfs2d_(0) {}
GLBackend::~GLBackend() {
if (!initialized_) {
return;
}
DestroyFonts();
DestroyVertexBuffers();
DestroyShaders();
@ -73,6 +77,8 @@ bool GLBackend::Init() {
return false;
}
initialized_ = true;
InitTextures();
InitShaders();
InitVertexBuffers();

View File

@ -33,8 +33,6 @@ struct BackendState {
BackendState()
: video_width(0),
video_height(0),
ta_width(0),
ta_height(0),
depth_mask(true),
depth_func(DEPTH_NONE),
cull_face(CULL_BACK),
@ -43,12 +41,8 @@ struct BackendState {
current_vao(0),
current_program(nullptr) {}
// gl context dimensions
int video_width;
int video_height;
// ta output dimensions
int ta_width;
int ta_height;
bool depth_mask;
DepthFunc depth_func;
CullFace cull_face;
@ -114,6 +108,7 @@ class GLBackend : public Backend {
void Flush2D();
GLContext &ctx_;
bool initialized_;
BackendState state_;
GLuint textures_[MAX_TEXTURES];
GLuint white_tex_;