The operational memory is filled until the DS hangs



  • The point is, some function distinguishes memory but does not remove it. I also know that the problem is drawing Window's responsibilities or functions that draw for themselves.

    I'll put the reference code on possibly problematic functions here, and the rest of the code on pastebin.

    void Window::draw(Object toDraw)
    {
    SDL_RenderCopy(coreRenderer, convertSurfaceToTexture(toDraw.getSurface(), coreRenderer), NULL, NULL);
    }
    

    SDL_Texture *convertSurfaceToTexture(SDL_Surface *image, SDL_Renderer *ren)
    {
    SDL_Texture *texture;
    texture = SDL_CreateTextureFromSurface(ren, image);
    if(texture == nullptr){
    std::cout << "Ошибка конвертирования SDL_Surface в SDL_Texture: " << "\n\t" << SDL_GetError() << std::endl;
    exit(1);
    }
    return texture;
    }

    Because I don't have scores of reputation, I will. http://pastebin.com/9zPKff9N where references will be made.



  • It's the right thing to remember, you create textures and never remove them. Every challenge. SDL_CreateTextureFromSurface relevant challenge SDL_DestroyTexture


    Your code must look like,

    auto texture = convertSurfaceToTexture(toDraw.getSurface(), coreRenderer);
    SDL_RenderCopy(coreRenderer, texture , NULL, NULL);
    SDL_DestroyTexture(texture);
    

    I'd do it all through. unique_ptrbut it's up to you.

    P.S. I don't know about SDL, but in the logic of things, the texture can be removed at this stage.




Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2