Hey ihr Spieleprogrammierer,
ich bekomme jedes mal wenn ich mein Programm schließe folgende Expression:
_BLOCK_TYPE_IS_VALID(pHeap->nBlockUse)
Da google mir sagte das ich wohl irgendwo ein Memoryleak haben wollte habe ich das mit _CrtCheckMemory() geprüft und 1 zurückbekommen, also habe ich mich auf die Suche nach dem Leak gemacht. Nach 2 Stunden suche bin ich Mental und Hitzebedingt total zerfressen und hoffe jetzt hier auf Hilfe.
Mein Programm umfasst eine Klasse zum laden von Sprites und die main.cpp welche ein Surface besitzt mit dem ich arbeite und welches ich ausgeben lasse.
CSprite.h:
|
C-/C++-Quelltext
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
|
#pragma once
#include <SDL.h>
#include <string>
class CSprite
{
private:
SDL_Rect position;
SDL_Surface *display;
public:
int moveSprite();
void drawSurface(SDL_Surface* source);
CSprite(int x, int y, std::string displayPath);
~CSprite(void);
};
|
CSprite.cpp
|
C-/C++-Quelltext
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
|
#include "Sprite.h"
CSprite::CSprite(int x, int y, std::string displayPath)
{
display = NULL;
position.x = x;
position.y = y;
display = SDL_LoadBMP(displayPath.c_str());
}
void CSprite::drawSurface(SDL_Surface* source)
{
SDL_BlitSurface(display, NULL, source, &position);
}
CSprite::~CSprite(void)
{
delete(display);
}
|
und die main.cpp:
|
C-/C++-Quelltext
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
|
#include <SDL.h>
#include <iostream>
#include "Sprite.h"
#ifdef _WIN32
#undef main
#endif
bool running = true;
int main(int argc, char *argv[]){
//Initialise
SDL_Init(SDL_INIT_EVERYTHING);
SDL_Surface *screen = NULL;
CSprite *sprite = new CSprite(10, 10, "background.bmp");
//Load
screen = SDL_SetVideoMode(640, 480, 32, SDL_SWSURFACE);
while( running )
{
sprite->drawSurface(screen);
// Update Screen
SDL_Flip(screen);
//Checking for Events(case of closing the window)
SDL_Event event;
if(SDL_PollEvent(&event))
{
if(event.type == SDL_QUIT)
{
running = false;
}
}
std::cout << _CrtCheckMemory();
}
delete(screen);
delete(sprite);
SDL_Quit();
return 0;
}
|
Freu mich über jeden Hilfevorschlag.
Mit freundlichen Grüßen
Horius