SDL_CreateRGBSurface Errors

I have the following problem:

I have written two Methods of a class Load_Image:

First method creates a Surface Image_Surface which then can be delivered
to external application entities by getSurface().

Load_File::Load_File( string Filename )

{

  this->Image_Surface = NULL;  // So we have a declaration SDL_Surface* 

Image_Surface in our class.

  // now we create a SDL_Surface, first checking if video system has been 

initialized…

  if ( SDL_WasInit( SDL_INIT_VIDEO ) & SDL_INIT_VIDEO == false ) 

{
  
  if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) 

    { 
      
      string error = "Could not initialize SDL" ; 
      
      cout << error << endl;

    } 
  
}

  else { cout << "video system already initialized." << endl; }
  


  SDL_Surface * Display_Surface = SDL_SetVideoMode ( 1, 1, 24, 

SDL_SWSURFACE ); // SDL_CreateRGBSurface needs this call

  if ( Display_Surface == NULL ) { cout << "could not initialize video 

surface." << endl ; }

  this->Image_Surface                 = SDL_CreateRGBSurface ( 

SDL_SWSURFACE , 640, 480, 24,
RMASK,
GMASK, BMASK, AMASK );

  if ( Image_Surface == NULL ) { cout << "could not initialize image 

surface." << endl ; }

  cout << "Adress of Pointer in Meth: "  << &Image_Surface << endl;
  cout << "Pointing to adress in Meth: " << Image_Surface << endl;
  cout << "value of object in Meth: "    <<  Image_Surface->w << 

Image_Surface->h << endl;

}

SDL_Surface * Load_File::getSurface()

{

return this->Image_Surface;

}

Now, if i call those methods from my main method by:----------------------------

  Load_File   * Loader  = new Load_File( Filepaths[pos] + Filenames[pos] );

  SDL_Surface * Surface = Loader->getSurface();
       
  cout << "Adress of Pointer in Main: "  << &Surface << endl;
  cout << "Pointing to adress in Main: " << Surface << endl;
  cout << "Adress of object in Main: "   << &(*Surface) << endl;
  cout << "value of object in Main: "    <<  Surface->w << Surface->h << 

endl;

it seems, that the Surface was vanished from memory, because
the ouputs of the cout lines is not the same:
Especially the access to the surface->w and surface->h are not the same:

video system already initialized.
Adress of Pointer in Meth: 0xbfffe5bc
Pointing to adress in Meth: 0x815fb58
Adress of object in Meth: 0x815fb58
value of object in Meth: 640480

Adress of Pointer in Main: 0xbfffe5f8
Pointing to adress in Main: 0x8208178
Adress of object in Main: 0x8208178
value of object in Main: 136291400136215912

the pointer which gets delivered to the main method doesnt seem to point
to a initialized surface, but to a random memory block with garbage data.

What is happening here?

Thx in advance

Axel

Axel <uh5d rz.uni-karlsruhe.de> writes:

Problem solved.