title: Process finished with exit code -1073740940 (0xC0000374) [CLion + SDL2]
body: <p>While I'm trying to close program, I want to delete dynamic SDL_surface array as usual through the for-loop, but program finishes with exit code -1073740940. When I commenting this loop, program closes with 0 exit code. So, what's the problem? Here is code: </p>
  
  <pre><code>void close(SDL_Window* window, SDL_Surface* surface, SDL_Surface* keys[]) {
  //free memory
  for( int i = 0; i &lt; KEY_PRESS_SURFACE_TOTAL; ++i )
  {
      //KEY_PRESS_SURFACE_TOTAL is defined in enum
      SDL_FreeSurface(keys[i]);
      keys[i] = nullptr;
  }
  
  SDL_FreeSurface(surface);
  surface = nullptr;
  
  SDL_DestroyWindow(window);
  window = nullptr;
  
  SDL_Quit();
  </code></pre>
  
  <p>I'm a beginner, so I'm just trying to learn SDL2 basics.</p>
  
  <p>UPDATE:
  Here is enum section code: </p>
  
  <pre><code>enum KeyPressSurfaces {
  KEY_PRESS_SURFACE_DEFAULT,
  KEY_PRESS_SURFACE_UP,
  KEY_PRESS_SURFACE_DOWN,
  KEY_PRESS_SURFACE_LEFT,
  KEY_PRESS_SURFACE_RIGHT,
  KEY_PRESS_SURFACE_TOTAL };
  </code></pre>
  
  <p>Also here's the using this array in code: </p>
  
  <pre><code>bool loadMedia(SDL_Surface* keys[]) {
  bool success = true;
  
  keys[KEY_PRESS_SURFACE_DEFAULT] = loadSurface("images/press.bmp");
  if( keys[KEY_PRESS_SURFACE_DEFAULT] == NULL ) {
      std::cout &lt;&lt; "Failed to load default image!\n";
      success = false;
  } //and so on...
  return success; }
  </code></pre>
  
  <p>In main section...</p>
  
  <pre><code>SDL_Surface* gKeyPressSurfaces[KEY_PRESS_SURFACE_TOTAL] = { };
  //creating window, surface etc.
  
  if ( !loadMedia(gKeyPressSurfaces) )
          std::cout &lt;&lt; "Failed to load media!\n";
      else {
          bool quit = false;
          SDL_Event event;
          gCurrentSurface = gKeyPressSurfaces[KEY_PRESS_SURFACE_DEFAULT];
  
          while ( !quit )
          {
              while (SDL_PollEvent(&amp;event) != 0)
              {
                  if ( event.type == SDL_KEYDOWN ) {
                      switch (event.key.keysym.sym) {
                              case SDLK_UP:
                                  gCurrentSurface = gKeyPressSurfaces[KEY_PRESS_SURFACE_UP];
                                  break; // and so on...
  </code></pre>
  
  <p>I did it following LazyFoo's SDL2 tutorials, so I don't understand why this not working.</p>