libnds: glTexImage2D use of DynamicArray
Posted: Wed Apr 08, 2009 11:08 pm
Hi,
I did a quick search and couldn't find this - but I'm new to these boards so apologies if this has already been covered. I'm using libnds source version 1.3.3.
glTexImage2D uses a dynamic array to track the association between texture name allocation and physical memory addresses. However, it appears to assume that the contents of the dynamic array are set to 0 after resizing - which is not guaranteed and can cause the routine to copy texture data to random memory (as occurred in my application).
DynamicArraySet (in dyanmicArray.h):
This uses realloc which does not guarantee the state of memory after reallocation. Adding a reference to <string.h> in dynamicArray.h and changing the routine to:
Of course, this has a slight performance overhead but there is currently no feedback to the caller of DynamicArraySet that a re-size operation has occurred and that data within the new area may be undefined.
If there's a better way of reporting things such as this then please let me know - I'm pretty new to the platform and very new to this forum.
I did a quick search and couldn't find this - but I'm new to these boards so apologies if this has already been covered. I'm using libnds source version 1.3.3.
glTexImage2D uses a dynamic array to track the association between texture name allocation and physical memory addresses. However, it appears to assume that the contents of the dynamic array are set to 0 after resizing - which is not guaranteed and can cause the routine to copy texture data to random memory (as occurred in my application).
DynamicArraySet (in dyanmicArray.h):
Code: Select all
void DynamicArraySet(DynamicArray *v, int index, void* item)
{
if(index >= v->cur_size)
{
v->cur_size *= 2;
v->data = (void**)realloc(v->data, sizeof(void*) * v->cur_size);
}
v->data[index] = item;
}
Code: Select all
void DynamicArraySet(DynamicArray *v, int index, void* item)
{
if(index >= v->cur_size)
{
v->data = (void**)realloc(v->data, sizeof(void*) * v->cur_size * 2);
memset(v->data + v->cur_size, 0, sizeof(void*) * v->cur_size);
v->cur_size *= 2;
}
v->data[index] = item;
}
If there's a better way of reporting things such as this then please let me know - I'm pretty new to the platform and very new to this forum.