Hallo,
ich entwickle gerade ein Jump&Run und habe dazu die Framework.hpp/.cpp, die Singleton.hpp und die CTimer.hpp/.cpp verwendet. Allerdings bekomme ich folgende Warnungen:
|
Quellcode
|
1
2
|
singleton.hpp(23): warning C4715: "TSingleton<CTimer>::Get": Nicht alle Steuerelementpfade geben einen Wert zurück.
singleton.hpp(23): warning C4715: "TSingleton<CFramework>::Get": Nicht alle Steuerelementpfade geben einen Wert zurück.
|
zusammen mit dieser Fehlermeldung:
|
Quellcode
|
1
2
3
|
Eine Ausnahme (erste Chance) bei 0x012855c6 in Tower Run.exe: 0xC0000005: Zugriffsverletzung beim Lesen an Position 0xccccccd0.
Unbehandelte Ausnahme bei 0x012855c6 in Tower Run.exe: 0xC0000005: Zugriffsverletzung beim Lesen an Position 0xccccccd0.
Das Programm "[3604] Tower Run.exe: Systemeigen" wurde mit Code -1073741819 (0xc0000005) beendet.
|
Code ist 1:1 aus dem Buch in den 5 Dateien...
Framework.hpp
|
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
|
#ifndef FRAMEWORK_HPP
#define FRAMEWORK_HPP
#include <iostream>
#include "Singleton.hpp"
#include "Timer.hpp"
using namespace std;
#define g_pFramework CFramework::Get()
class CFramework : public TSingleton<CFramework>
{
public:
bool Init(int ScreenWidth, int ScreenHeight, int ColorDepth, bool bFullscreen);
void Quit();
void Update();
void Clear();
void Flip();
bool KeyDown(int Key_ID);
SDL_Surface *GetScreen() {return m_pScreen;}
private:
SDL_Surface *m_pScreen;
Uint8 *m_pKeystate;
};
#endif
|
Framework.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
|
#include "Framework.hpp"
bool CFramework::Init(int ScreenWidth, int ScreenHeight, int ColorDepth, bool bFullscreen)
{
//SDL initalisieren
if(SDL_Init (SDL_INIT_VIDEO | SDL_INIT_TIMER) == -1)
{
cout << "SDL konnte nicht initalisiert werden!" << endl;
cout << "Fehlermeldung: " << SDL_GetError() << endl;
Quit();
return false;
}
//Vollbild
if(bFullscreen == true)
{
m_pScreen = SDL_SetVideoMode(ScreenWidth, ScreenHeight, ColorDepth, SDL_HWSURFACE | SDL_DOUBLEBUF | SDL_FULLSCREEN);
} else
{
m_pScreen = SDL_SetVideoMode(ScreenWidth, ScreenHeight, ColorDepth, SDL_HWSURFACE | SDL_DOUBLEBUF);
}
if(m_pScreen == NULL)
{
cout << "Videomodus konnte nicht gesetzt werden!" << endl;
cout << "Fehlermeldung: " << SDL_GetError() << endl;
Quit();
return false;
}
m_pKeystate = SDL_GetKeyState(NULL);
return true;
}
void CFramework::Quit()
{
SDL_Quit();
}
void CFramework::Update()
{
g_pTimer->Update();
SDL_PumpEvents();
}
bool CFramework::KeyDown (int Key_ID)
{
return(m_pKeystate[Key_ID] ? true : false);
}
void CFramework::Clear()
{
SDL_FillRect(m_pScreen, NULL, SDL_MapRGB(m_pScreen->format, 0, 0, 0));
}
void CFramework::Flip()
{
SDL_Flip(m_pScreen);
}
|
Timer.hpp
|
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
|
#ifndef TIMER_HPP
#define TIMER_HPP
#include <SDL.h>
#include "Singleton.hpp"
#define g_pTimer CTimer::Get()
class CTimer : public TSingleton<CTimer>
{
public:
CTimer();
void Update();
float GetElapsed() {return m_fElapsed;}
private:
float m_fElapsed; //Zeit seit letztem Frame (von A - B)
float m_fCurTime; //Aktuelle Zeit (B)
float m_fLastTime;//Zeit des letzten Frame (A)
};
#endif
|
Timer.cpp
|
C-/C++-Quelltext
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
|
#include "Timer.hpp"
CTimer::CTimer()
{
m_fCurTime = 0.0f;
m_fLastTime = SDL_GetTicks()/1000.0f;
m_fElapsed = 0.0f;
}
void CTimer::Update()
{
m_fCurTime = SDL_GetTicks()/1000.0f;
m_fLastTime = m_fCurTime - m_fLastTime;
m_fLastTime = m_fCurTime;
}
|
Singleton.hpp
|
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
|
#ifndef TSINGLETON
#define TSINGLETON
template <class T>
class TSingleton
{
protected:
static T *m_pSingleton;
public:
virtual ~TSingleton()
{
}
inline static T* Get()
{
if(!m_pSingleton)
{
m_pSingleton = new T;
return m_pSingleton;
}
}
static void Del()
{
if(m_pSingleton)
{
delete(m_pSingleton);
m_pSingleton = NULL;
}
}
};
template <class T>
T* TSingleton<T>::m_pSingleton = 0;
#endif
|
Programm stoppt bei alle Punkten, die auf m_pScreen zugreifen (vor allem hier: SDL_Surface *GetScreen() {return m_pScreen;} )
Bekomme auch jedes Mal beim Starten nen Blackscreen. Programm ist dann nicht mal mehr mit Task-Manager killbar, muss also das Visual Studio oder den PC killen...