clean up allocated memory properly when raising Ruby exceptions upon object creation
This commit is contained in:
parent
9203a94a71
commit
8d8c9adcb3
@ -24,14 +24,15 @@ static void GLProgram_free(void * ptr)
|
|||||||
|
|
||||||
static VALUE GLProgram_new(int argc, VALUE * argv, VALUE klass)
|
static VALUE GLProgram_new(int argc, VALUE * argv, VALUE klass)
|
||||||
{
|
{
|
||||||
GLProgram * glprogram = new GLProgram();
|
GLuint id = glCreateProgram();
|
||||||
|
if (id == 0u)
|
||||||
glprogram->id = glCreateProgram();
|
|
||||||
if (glprogram->id == 0u)
|
|
||||||
{
|
{
|
||||||
rb_raise(rb_eRuntimeError, "Error allocating GL program object");
|
rb_raise(rb_eRuntimeError, "Error allocating GL program object");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
GLProgram * glprogram = new GLProgram();
|
||||||
|
glprogram->id = id;
|
||||||
|
|
||||||
VALUE rv = Data_Wrap_Struct(klass, NULL, GLProgram_free, glprogram);
|
VALUE rv = Data_Wrap_Struct(klass, NULL, GLProgram_free, glprogram);
|
||||||
rb_obj_call_init(rv, argc, argv);
|
rb_obj_call_init(rv, argc, argv);
|
||||||
|
|
||||||
|
@ -79,7 +79,6 @@ static void GLShader_free(void * ptr)
|
|||||||
|
|
||||||
static VALUE GLShader_new(VALUE klass, VALUE type, VALUE source)
|
static VALUE GLShader_new(VALUE klass, VALUE type, VALUE source)
|
||||||
{
|
{
|
||||||
GLShader * glshader = new GLShader();
|
|
||||||
GLenum shader_type;
|
GLenum shader_type;
|
||||||
|
|
||||||
if (type == ID2SYM(rb_intern("vertex")))
|
if (type == ID2SYM(rb_intern("vertex")))
|
||||||
@ -99,10 +98,13 @@ static VALUE GLShader_new(VALUE klass, VALUE type, VALUE source)
|
|||||||
type_cstr);
|
type_cstr);
|
||||||
}
|
}
|
||||||
|
|
||||||
glshader->id = create_shader(shader_type,
|
GLuint id = create_shader(shader_type,
|
||||||
RSTRING_PTR(source),
|
RSTRING_PTR(source),
|
||||||
RSTRING_LEN(source));
|
RSTRING_LEN(source));
|
||||||
|
|
||||||
|
GLShader * glshader = new GLShader();
|
||||||
|
glshader->id = id;
|
||||||
|
|
||||||
return Data_Wrap_Struct(klass, NULL, GLShader_free, glshader);
|
return Data_Wrap_Struct(klass, NULL, GLShader_free, glshader);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -72,19 +72,22 @@ static VALUE Window_new(VALUE klass)
|
|||||||
}
|
}
|
||||||
|
|
||||||
Init_SDL();
|
Init_SDL();
|
||||||
Window * window = new Window();
|
|
||||||
window->sdl_window = SDL_CreateWindow("jes",
|
SDL_Window * sdl_window =
|
||||||
|
SDL_CreateWindow("jes",
|
||||||
SDL_WINDOWPOS_UNDEFINED,
|
SDL_WINDOWPOS_UNDEFINED,
|
||||||
SDL_WINDOWPOS_UNDEFINED,
|
SDL_WINDOWPOS_UNDEFINED,
|
||||||
WIDTH,
|
WIDTH,
|
||||||
HEIGHT,
|
HEIGHT,
|
||||||
SDL_WINDOW_OPENGL | SDL_WINDOW_RESIZABLE);
|
SDL_WINDOW_OPENGL | SDL_WINDOW_RESIZABLE);
|
||||||
if (window->sdl_window == NULL)
|
if (sdl_window == NULL)
|
||||||
{
|
{
|
||||||
free(window);
|
|
||||||
rb_raise(rb_eRuntimeError, "Failed to create SDL window");
|
rb_raise(rb_eRuntimeError, "Failed to create SDL window");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Window * window = new Window();
|
||||||
|
window->sdl_window = sdl_window;
|
||||||
|
|
||||||
(void)SDL_GL_CreateContext(window->sdl_window);
|
(void)SDL_GL_CreateContext(window->sdl_window);
|
||||||
|
|
||||||
Init_OpenGL();
|
Init_OpenGL();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user