1

I'm having difficulties with creating dynamic table of SDL_Surface. Take a look at that code:

SDL_Surface **testA = new SDL_Surface *[2];
for(int i=0;i<2;i++)
    testA[i] = new SDL_Surface;
SDL_Surface* testB[2];

As far as i'm concerned, TestA and textB should look identically. But Visual Studio locals look like that: image

How should I fix that?

Mat
  • 202,337
  • 40
  • 393
  • 406
Greg Witczak
  • 1,634
  • 4
  • 27
  • 56

2 Answers2

2

Try this:

    int size=2;
    SDL_Surface** testA ; 
    testA  = new SDL_Surface*[size];  

    for (int i = 0; i < size; i++) 
    { 
      surface[i] = NULL; //  here, surface[i] is the kth pointer, not an SDL_Surface 
   // surface[i] = SDL_CreateRGBSurface ( /* set your parameters */ );
    } 


    // Of course, somewhere later in the code, you'll need to free the memory ... 
    for (i = 0; i < size; i++) 
    { 
    SDL_FreeSurface(testA [i]); 
    testA [i] = NULL; 
    } 

    delete testA ; 
Software_Designer
  • 8,490
  • 3
  • 24
  • 28
1

SDL_Surface shouldn't be allocated using new, but using the functions from the SDL API (e.g. SDL_CreateRGBSurface, SDL_ConvertSurface...) which will allocate it and initialize it properly.

If the problem is about the way Visual Studio debugger displays dynamically allocated arrays, you should look at that question: How to display a dynamically allocated array in the Visual Studio debugger?

Community
  • 1
  • 1
alexisdm
  • 29,448
  • 6
  • 64
  • 99