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)
|
||||
{
|
||||
GLProgram * glprogram = new GLProgram();
|
||||
|
||||
glprogram->id = glCreateProgram();
|
||||
if (glprogram->id == 0u)
|
||||
GLuint id = glCreateProgram();
|
||||
if (id == 0u)
|
||||
{
|
||||
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);
|
||||
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)
|
||||
{
|
||||
GLShader * glshader = new GLShader();
|
||||
GLenum shader_type;
|
||||
|
||||
if (type == ID2SYM(rb_intern("vertex")))
|
||||
@ -99,10 +98,13 @@ static VALUE GLShader_new(VALUE klass, VALUE type, VALUE source)
|
||||
type_cstr);
|
||||
}
|
||||
|
||||
glshader->id = create_shader(shader_type,
|
||||
GLuint id = create_shader(shader_type,
|
||||
RSTRING_PTR(source),
|
||||
RSTRING_LEN(source));
|
||||
|
||||
GLShader * glshader = new GLShader();
|
||||
glshader->id = id;
|
||||
|
||||
return Data_Wrap_Struct(klass, NULL, GLShader_free, glshader);
|
||||
}
|
||||
|
||||
|
@ -72,19 +72,22 @@ static VALUE Window_new(VALUE klass)
|
||||
}
|
||||
|
||||
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,
|
||||
WIDTH,
|
||||
HEIGHT,
|
||||
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");
|
||||
}
|
||||
|
||||
Window * window = new Window();
|
||||
window->sdl_window = sdl_window;
|
||||
|
||||
(void)SDL_GL_CreateContext(window->sdl_window);
|
||||
|
||||
Init_OpenGL();
|
||||
|
Loading…
x
Reference in New Issue
Block a user