[Mesa-dev] [BUG]: calloc (nmemb=1, size=0)
Lucas Stach
dev at lynxeye.de
Fri Aug 3 04:07:22 PDT 2012
Am Freitag, den 03.08.2012, 07:57 +0200 schrieb Johann Klammer:
> Hello,
>
> I tried to replace the memory allocator for a program
> linked against mesa. With the libc allocators the app shows some
> textured and shaded triangles, but with the custom allocators, it's all
> black triangles. Sorry, I cannot post the program source as it is rather
> large, but will try to come up with a minimal test if this is necessary.
>
> The custom allocator returns NULL for zero-sized requests.
> The problem goes away if I change the allocator to return some memory.
>
> Mesa Version: 8.0.3
>
> Symptoms:
> all black triangles.
>
> The relevant snippet seems to be:
>
> 4674 t->immediates = (struct ureg_src *)CALLOC(program->num_immediates
> * sizeof(struct ureg_src));
> 4675 if (t->immediates == NULL) {
> 4676 ret = PIPE_ERROR_OUT_OF_MEMORY;
> 4677 goto out;
> 4678 }
>
[...]
Does the patch below help?
--
From: Lucas Stach <dev at lynxeye.de>
Date: Fri, 3 Aug 2012 12:55:20 +0200
Subject: [PATCH] st/mesa: fix immediate emission with custom allocator
---
src/mesa/state_tracker/st_glsl_to_tgsi.cpp | 24 +++++++++++++-----------
1 Datei geändert, 13 Zeilen hinzugefügt(+), 11 Zeilen entfernt(-)
diff --git a/src/mesa/state_tracker/st_glsl_to_tgsi.cpp b/src/mesa/state_tracker/st_glsl_to_tgsi.cpp
index fcd69b1..f426f45 100644
--- a/src/mesa/state_tracker/st_glsl_to_tgsi.cpp
+++ b/src/mesa/state_tracker/st_glsl_to_tgsi.cpp
@@ -4714,18 +4714,20 @@ st_translate_program(
/* Emit immediate values.
*/
- t->immediates = (struct ureg_src *)CALLOC(program->num_immediates * sizeof(struct ureg_src));
- if (t->immediates == NULL) {
- ret = PIPE_ERROR_OUT_OF_MEMORY;
- goto out;
- }
- i = 0;
- foreach_iter(exec_list_iterator, iter, program->immediates) {
- immediate_storage *imm = (immediate_storage *)iter.get();
- assert(i < program->num_immediates);
- t->immediates[i++] = emit_immediate(t, imm->values, imm->type, imm->size);
+ if (program->num_immediates) {
+ t->immediates = (struct ureg_src *)CALLOC(program->num_immediates * sizeof(struct ureg_src));
+ if (t->immediates == NULL) {
+ ret = PIPE_ERROR_OUT_OF_MEMORY;
+ goto out;
+ }
+ i = 0;
+ foreach_iter(exec_list_iterator, iter, program->immediates) {
+ immediate_storage *imm = (immediate_storage *)iter.get();
+ assert(i < program->num_immediates);
+ t->immediates[i++] = emit_immediate(t, imm->values, imm->type, imm->size);
+ }
+ assert(i == program->num_immediates);
}
- assert(i == program->num_immediates);
/* texture samplers */
for (i = 0; i < ctx->Const.MaxTextureImageUnits; i++) {
--
1.7.11.2
More information about the mesa-dev
mailing list