gbadev.org forum archive

This is a read-only mirror of the content originally found on forum.gbadev.org (now offline), salvaged from Wayback machine copies. A new forum can be found here.

DS development > Texture corruption after glResetTextures()

#167145 - Kath - Tue Mar 03, 2009 4:52 pm

Hi again,

I'm having a problem with getting corrupted textures when loading them after glResetTextures() has been called. I have banks A and B assigned to textures. The first game state loads 224k of textures and this works fine. When this state ends it calls glResetTextures() and then the next state loads it's textures. However as this state starts getting close to the end of VRAM_A (128k) the first texture loaded starts getting corrupted, I can see the shape of the last texture uploaded appear on the first.

It seems that after calling glResetTextures() only Bank A is used and as it gets filled libnds goes back to the start of it. If I set the second state to be the first it loads the same textures without a problem. I've been trying to figure this out for a few hours so here are all of the textures I load (in the order they are loaded):

In the first game state I load:

256x256 (256col) (64k) ~ 64k
256x256 (256col) (64k) ~ 128k - VRAM_A full.
256x256 (256col) (64k) ~ 192k - Starts in VRAM_B.
256x256 (16col) (32k) ~ 224k

In the second game state I load:

256x256 (256col) (64k) ~ 64k
256x256 (16col) (32k) ~ 96k
128x128 (16col) (8k) ~ 104k
128x128 (16col) (8k) ~ 112k
128x128 (16col) (8k) ~ 120k <- Corruption starts here.

I thought it might have been my texture manager but it all seems to be updating properly, the handles/addresses it gets for each state are:

First state:
- Texture name: 1
- Texture name: 2
- Texture name: 3
- Texture name: 4
- Palette address: 0
- Palette address: 512
- Palette address: 1024
- Palette address: 1536

Second state:
- Texture name: 1
- Texture name: 2
- Texture name: 3
- Texture name: 4
- Texture name: 5
- Palette address: 0
- Palette address: 512
- Palette address: 544
- Palette address: 576
- Palette address: 608

Sorry about the long post, thought more information would be helpful. Is there anything else I should be doing other than clearing my saved names and calling glResetTextures()? Thanks for any pokes in the right direction.

#167167 - elhobbs - Wed Mar 04, 2009 2:43 pm

I may be wrong, but there looks like there is an issue with the glResetTextures function - should it clear out the dynamic array texturePtrs? since it is not cleared out during a reset it looks like it will reuse the texture vram from the texture at that name before the reset which could lead to the issues you are experiencing.

#167335 - Zalo - Mon Mar 09, 2009 11:22 am

Yes... I updated to the last version on libnds with a lot of issues and I am also having a problem with textures that I think may be related to this. Anybody fixed it?
_________________
-----
Zalo

#167507 - Zalo - Sun Mar 15, 2009 9:02 pm

you were right elhobbs

This is how glResetTextures should look like:

Code:
//---------------------------------------------------------------------------------
void glResetTextures(void) {
//---------------------------------------------------------------------------------
  int i;

   glGlob->activeTexture = 0;
   glGlob->nextBlock = (uint32*)0x06800000;
   glGlob->nextPBlock = 0;
   glGlob->nameCount = 1;

  for(i = 0; i < glGlob->texturePtrs.cur_size; i++)
      DynamicArraySet(&glGlob->texturePtrs, i, (void*)0);
}


After that change everything seems to be working again :)
_________________
-----
Zalo