Anyone got any ideas where 4k a sec is coming from?

Started by
40 comments, last by Brain 8 years, 10 months ago

I've got a basic program running SDL2 that loads a surface and a class wrapper that handles object creation/texture loading. Before I even start to generate objects SDL is streaming extra memory at around 4k a second.

Is this a known issue or could I have created some weird loop. I don't call any new objects in my code apart from the class to hold the objects that will be created:

pAsset_explosions= new GeneralObject("disposable_explosion.png", screenCoords);
pAsset_explosions->fLoadImages(mpRenderer);
If you get near a point, make it!
Advertisement

Do you delete that pointer?

Yes when the program closes I release it with delete.

It's not that (i assume) that's causing it it's happening when the program is running and before anything else has been created using new.

How do I capture a problem like this in code blocks?

If you get near a point, make it!

you're not loading that explosion every frame are you?

Nope it's only initialized once along with the rest of the SDL basics (surface etc).

If you get near a point, make it!

Why not show a little more code if it is a lot consider paste bin

Okay code time...


#include "CApp.h"
 
int main(int argc, char* argv[])
{
return CApp::GetInstance()->OnExecute(argc, argv);
}

#ifndef CAPP_H_INCLUDED
#define CAPP_H_INCLUDED
 
#include <SDL2/SDL.h>
#include <SDL2/SDL_image.h>
#include <SDL2/SDL_ttf.h>
 
#include <sstream>
#include <iostream>
#include <stdio.h>
#include <string>
 
#include <memory>
 
#include "Texture.h"
#include "TextureText.h"
#include "LoadMedia.h"
 
class Texture;
class LoadMedia;
 
class CApp
{
//private:
    protected:
        static const int WindowWidth = 1024;
        static const int WindowHeight = 768;
 
        SDL_Window* Window = NULL;
        SDL_Renderer* Renderer = NULL;
 
        bool bLoadMedia= false;
 
    private:
        static CApp Instance;
        bool Running = true;
 
    public:
        CApp() { }
        ~CApp() { }
 
        bool OnInit();
 
        bool fLoadMedia()
        {
            WindowSize.w = SDL_GetWindowSurface(Window)->w;
            WindowSize.h = SDL_GetWindowSurface(Window)->h;
            SDL_Rect screenCoords= {0, 0, WindowSize.w, WindowSize.h};
 
            if(bLoadMedia)
            {
                mediaAssets= new LoadMedia(Renderer, MainTTfont, screenCoords);
                if(mediaAssets->fInitializeMedia())
            }
            return true;
        }
 
        void OnEvent(SDL_Event* Event)
        {
            if(Event->type == SDL_QUIT) Running = false;
            if(Event->type == SDL_KEYDOWN)
            {
                switch(Event->key.keysym.sym)
                {
                    case SDLK_ESCAPE:
                        Running = false;
                    break;
                }
            }
 
            if(bLoadMedia)
                mediaAssets->fOnMediaEvent(Event);
        }
 
        void OnLoop()
        {
            ///UPDATE ASSETS
            if(bLoadMedia)
                mediaAssets->fCheckMediaAssets();
        }
 
        void OnRender()
        {
            SDL_SetRenderDrawColor(Renderer, 100, 0x00, 200, 0xFF);
            SDL_RenderClear(Renderer);
 
            if(bLoadMedia)
                mediaAssets->fRenderAssets();
 
            SDL_RenderPresent(Renderer); //Use this function to update the screen with rendering performed.
        }
 
        void OnCleanup()
        {
            if(bLoadMedia)
                mediaAssets->fCleanupAssets();
 
            if(Renderer)
            {
                SDL_DestroyRenderer(Renderer);
                Renderer = NULL;
            }
 
            if(Window)//All screen surfaces are de-constructed by SDL_DestroyWindow
            {
                SDL_DestroyWindow(Window);
                Window = NULL;
            }
 
            IMG_Quit();
            SDL_Quit();
        }
 
    public:
int OnExecute(int argc, char* argv[]);
 
public:
static CApp* GetInstance();
        int intAval = 0;
 
    public:
        SDL_Rect WindowSize;
 
        LoadMedia* mediaAssets= NULL;
        TTF_Font* MainTTfont= NULL;
        SDL_Surface* LoadSurface= NULL;
};
 
#endif // CAPP_H_INCLUDED
If you get near a point, make it!

 
#include "capp.h"
 
CApp CApp::Instance;
 
int CApp::OnExecute(int argc, char* argv[])
{
    if(!OnInit()) return 0;
 
SDL_Event Event;
 
while(Running) {
while(SDL_PollEvent(&Event) != 0) {
OnEvent(&Event);
}
 
OnLoop();
OnRender();
 
SDL_Delay( 60 );
}
 
OnCleanup();
 
return 1;
}
 
CApp* CApp::GetInstance() { return &CApp::Instance; }
If you get near a point, make it!

#include "capp.h"
 
bool CApp::OnInit() {
    if(SDL_Init(SDL_INIT_VIDEO) < 0) {
     printf("Unable to Init SDL: %s", SDL_GetError());
     return false;
    }
 
    if(!SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, "1")) {
        printf("Unable to Init hinting: %s", SDL_GetError());
    }
 
    if((Window = SDL_CreateWindow(
     "My SDL Game",
     SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED,
WindowWidth, WindowHeight, SDL_WINDOW_SHOWN)
    ) == NULL) {
     return false;
    }
 
    LoadSurface = SDL_GetWindowSurface(Window);
 
    if((Renderer = SDL_CreateRenderer(Window, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC )) == NULL) {
        return false;
    }
 
// Initialize image loading for PNGs
if(!(IMG_Init(IMG_INIT_PNG) & IMG_INIT_PNG))
    {
return false;
}
 
if(TTF_Init()==-1)
    {
        dMSG("SDL_ttf could not initialize! SDL_ttf Error: ", 0);
    }
 
 
    if(!fLoadMedia())
    {
        return false;
    }
 
    return true;
}
 
If you get near a point, make it!

Just noticed that this is happening even when I stop the media (images and classes to create them) loading, is this the application instance or a windows thing?

4788k

4792k

4804k

4808k

it does this in task manager over the course of about 10-20 seconds and keeps going indefinitely, puzzled by this.

If you get near a point, make it!

This topic is closed to new replies.

Advertisement