diff --git a/src/glsl/glsl_symbol_table.h b/src/glsl/glsl_symbol_table.h index 2528264..3dfddb1 100644 --- a/src/glsl/glsl_symbol_table.h +++ b/src/glsl/glsl_symbol_table.h @@ -58,7 +58,8 @@ public: void *table; table = ralloc_size(ctx, size); - assert(table != NULL); + if (!table) + throw std::bad_alloc(); ralloc_set_destructor(table, (void (*)(void*)) _glsl_symbol_table_destructor); diff --git a/src/glsl/glsl_types.h b/src/glsl/glsl_types.h index d545533..99b55ee 100644 --- a/src/glsl/glsl_types.h +++ b/src/glsl/glsl_types.h @@ -31,6 +31,7 @@ #include "main/mtypes.h" /* for gl_texture_index, C++'s enum rules are broken */ #ifdef __cplusplus +#include extern "C" { #endif @@ -130,7 +131,8 @@ struct glsl_type { void *type; type = ralloc_size(glsl_type::mem_ctx, size); - assert(type != NULL); + if (type == NULL) + throw std::bad_alloc(); return type; } diff --git a/src/mesa/program/ir_to_mesa.cpp b/src/mesa/program/ir_to_mesa.cpp index 293fe34..83cd1ae 100644 --- a/src/mesa/program/ir_to_mesa.cpp +++ b/src/mesa/program/ir_to_mesa.cpp @@ -3031,7 +3031,11 @@ _mesa_glsl_link_shader(struct gl_context *ctx, struct gl_shader_program *prog) } if (prog->LinkStatus) { - link_shaders(ctx, prog); + try { + link_shaders(ctx, prog); + } catch (const std::bad_alloc &ba) { + linker_error(prog, "out of memory while linking"); + } } if (prog->LinkStatus) { diff --git a/src/util/ralloc.h b/src/util/ralloc.h index 4b88f32..1d10d60 100644 --- a/src/util/ralloc.h +++ b/src/util/ralloc.h @@ -47,6 +47,7 @@ #define RALLOC_H #ifdef __cplusplus +#include extern "C" { #endif @@ -424,7 +425,8 @@ public: \ static void* operator new(size_t size, void *mem_ctx) \ { \ void *p = ralloc_size(mem_ctx, size); \ - assert(p != NULL); \ + if (!p) \ + throw std::bad_alloc(); \ if (!HAS_TRIVIAL_DESTRUCTOR(TYPE)) \ ralloc_set_destructor(p, _ralloc_destructor); \ return p; \