Advertisement

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

Started by March 31, 2015 06:12 PM
40 comments, last by Brain 9 years, 7 months ago

I don't see any place where you change the value of 'bLoadMedia' apart from when you initialize it.

does this delete the pointer to node originally created of is this now a dangling pointer?

sorry GD.net died 3 times when posting and then it locked me out, and then there was food!

If you get near a point, make it!
Advertisement
Surely if I have a newly created object to Node and a newly created object referenced by the node I have to delete both.
So why when I clear all with the destructor does it crash?



Node* pTBDel= head;
            delete pTBDel->current;///DELETE THE ITEM REFERENCE
            delete pTBDel;///DELETE THE POINTER
            head= head->next;
            count--;

If you get near a point, make it!

DUH!!! Don't delete the reference to head before moving it forwards, I put the delete before changing head's pointer reference.

            head= head->next; ///UPDATE THE SMEGGING REFERENCE FIRST
            delete pTBDel->current;///DELETE THE ITEM REFERENCE
            delete pTBDel;///DELETE THE POINTER
            //head= head->next;

Sorry to be a pain, I do try and solve these things myself generally but this one was driving me mad.

If you get near a point, make it!

And strangely enough was the cause of the other memory leak as well, I have no idea how they were linked as it shouldn't have been calling until input was passed to the program through the keyboard.

As always I have a lot to learn and no time to learn it in lol.

If you get near a point, make it!
Why are you calling `new' at all? You can write C++ in a simple style that allows for many fewer places to screw up. I've posted this list of principles before:

(1) Use standard containers (of objects, not pointers) instead of rolling your own data structures.
(2) Use a smart pointer (probably std::unique_ptr) when you need polymorphism.
(3) Be very clear about which object owns which resource, and release the resource in the object's destructor.

I haven't had a memory leak in many years.
Advertisement

Hindsight is a wonderful thing, sometimes you just need to be that kid falling flat on your face to realize that's why people don't do it.

But... I have a vision, it is a very stubborn one. Until I know I can't do it, i'm not taking anyone else's word on it ;)

If you get near a point, make it!

I'm still no closer to figuring out why my program is causing infinitely exponential 4k from what seems to be SDL_RenderPresent(Renderer);

Any ideas, i've isolated the issue right down to basics:

 
#include <SDL2/SDL.h>
 
#include <iostream>
#include <stdio.h>
 
#define WINDOW_HANDLE "BasicEngine strip down"
 
///MAIN VARIABLES
bool appRunning= true;
const int WindowWidth = 1024;
const int WindowHeight = 768;
SDL_Rect screenCoords;
 
SDL_Window* Window= NULL;
SDL_Renderer* Renderer= NULL;
 
///FORWARD DECLARATIONS
bool OnInit();
bool fLoadMedia();
void OnEvent(SDL_Event* Event);
void OnLoop();
void OnRender();
void OnCleanup();
 
int main(int argc, char* argv[])
{
    if(!OnInit()) { return false; }
 
    SDL_Event Event;
 
while(appRunning)
{
while(SDL_PollEvent(&Event)!= 0)
        {
OnEvent(&Event);
}
 
OnRender(); ///WTF ARE THESE CAUSING EXPONENTIAL MEMORY CREATION!?
}
 
OnCleanup();
 
return false;
}
 
bool OnInit()
{
    if(SDL_Init(SDL_INIT_VIDEO)!= 0)
    {
        printf("Unable to Init SDL: %s", SDL_GetError());
        return false;
    } else {
        if( !SDL_SetHint( SDL_HINT_RENDER_SCALE_QUALITY, "1" ) )
{
printf( "Warning: Linear texture filtering not enabled!" );
}
 
        if(
        (Window=
        SDL_CreateWindow(
        WINDOW_HANDLE,
        SDL_WINDOWPOS_UNDEFINED,
        SDL_WINDOWPOS_UNDEFINED,
        WindowWidth,
        WindowHeight,
        SDL_WINDOW_SHOWN)
        )==nullptr)
        {
            return false;
        }
 
        if((Renderer = SDL_CreateRenderer(Window, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC ))== nullptr) {
            return false;
        }
    }
 
    return true;
}
 
void OnEvent(SDL_Event* Event)
{
    if(Event->type== SDL_QUIT) appRunning= false;
    if(Event->type== SDL_KEYDOWN)
    {
        switch(Event->key.keysym.sym)
        {
            case SDLK_ESCAPE:
                appRunning= false;
            break;
        }
    }
}
 
void OnRender()
{
    ///WTF ARE THESE CAUSING EXPONENTIAL MEMORY CREATION!?
    SDL_SetRenderDrawColor(Renderer, 100, 0x00, 200, 0xFF);
    SDL_RenderClear(Renderer);
 
    ///UPDATE THE SCREEN
    SDL_RenderPresent(Renderer);
}
 
void OnCleanup()
{
    if(Renderer)
    {
        SDL_DestroyRenderer(Renderer);
        Renderer= nullptr;
    }
 
    if(Window)
    {
        SDL_DestroyWindow(Window);
        Window= nullptr;
    }
    
    SDL_Quit();
}
 
If you get near a point, make it!
Is this causing an actual problem? Other than the potentially eronous values in taskmanager?

When writing any software, there are too many actual challenges to spend time chasing ghosts.
By any chance do you have to free the event raised by sdl_pollevent?

This topic is closed to new replies.

Advertisement