Bonjour,
Débutant en programmation C++, SDL et OpenGL, je cherche à réaliser un petit shooter 2D.
Je constate déjà que mon tout petit programme souffre d'une fuite mémoire régulière d'environ 4ko toutes les 2 secondes. Avant que ce genre de problèmes n'enflent jusqu'à devenir ingérable, et pour bien comprendre le fonctionnement de ce langage et de ces modules, je voulais vous soumettre mes trois fonctions principales pour savoir si vous pouviez détecter ou m'aider à détecter l'origine de cette fuite.
Je me suis inspiré de ce tuto pour mon moteur SDL et j'ai donc commenté l'appel aux fonctions "Think" et "Render" contenant vraiment le code de mon jeu, afin de cibler le problème.
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78 /** The main loop. **/ void CEngine::Start() { m_lLastTick = SDL_GetTicks(); m_bQuit = false; // Main loop: loop forever. while ( !m_bQuit ) { // Handle mouse and keyboard input HandleInput(); if ( m_bMinimized ) { // Release some system resources if the app. is minimized. #if _WIN32 WaitMessage(); // pause the application until focus in regained #endif } else { // Do some thinking DoThink(); // Render stuff DoRender(); //Attends la fin de la frame SDL_Delay(1000/30 - (SDL_GetTicks() - m_lLastTick)); } } End(); } /** Handles the updating routine. **/ void CEngine::DoThink() { long iElapsedTicks = SDL_GetTicks() - m_lLastTick; m_lLastTick = SDL_GetTicks(); //Think( iElapsedTicks ); m_iFPSTickCounter += iElapsedTicks; } /** Handles the rendering and FPS calculations. **/ void CEngine::DoRender() { ++m_iFPSCounter; if ( m_iFPSTickCounter >= 1000 ) { m_iCurrentFPS = m_iFPSCounter; m_iFPSCounter = 0; m_iFPSTickCounter = 0; } // Lock surface if needed if ( SDL_MUSTLOCK( m_pScreen ) ) if ( SDL_LockSurface( m_pScreen ) < 0 ) return; // Effacer le tampon des couleurs glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glClearDepth(0.0f); glLoadIdentity(); //Render( GetSurface() ); // Unlock if needed if ( SDL_MUSTLOCK( m_pScreen ) ) SDL_UnlockSurface( m_pScreen ); // Tell SDL to update the whole gScreen //SDL_Flip( m_pScreen ); glFlush(); SDL_GL_SwapBuffers(); }
Merci d'avance.
Eric 'Henn' Niubo
Partager