Ich habe in einer SDL Anwendung einen seltsamen Fehler bekommen.
Die Ausgabe des Debuggers lautet:
"Projekt.exe": "D:\Admin\Documents\Visual Studio 2010\Projects\Projekt\Debug\Projekt.exe" geladen, Symbole wurden geladen.
"Projekt.exe": "C:\Windows\SysWOW64\ntdll.dll" geladen, Cannot find or open the PDB file
"Projekt.exe": "C:\Program Files\AVAST Software\Avast\snxhk.dll" geladen, Cannot find or open the PDB file
"Projekt.exe": "C:\Windows\SysWOW64\kernel32.dll" geladen, Cannot find or open the PDB file
"Projekt.exe": "C:\Windows\SysWOW64\KernelBase.dll" geladen, Cannot find or open the PDB file
"Projekt.exe": "D:\Admin\Documents\Visual Studio 2010\Projects\Projekt\Debug\SDL.dll" geladen, Die Binärdaten wurden nicht mit Debuginformationen erstellt.
"Projekt.exe": "C:\Windows\SysWOW64\advapi32.dll" geladen, Cannot find or open the PDB file
"Projekt.exe": "C:\Windows\SysWOW64\msvcrt.dll" geladen, Cannot find or open the PDB file
"Projekt.exe": "C:\Windows\SysWOW64\sechost.dll" geladen, Cannot find or open the PDB file
"Projekt.exe": "C:\Windows\SysWOW64\rpcrt4.dll" geladen, Cannot find or open the PDB file
"Projekt.exe": "C:\Windows\SysWOW64\sspicli.dll" geladen, Cannot find or open the PDB file
"Projekt.exe": "C:\Windows\SysWOW64\cryptbase.dll" geladen, Cannot find or open the PDB file
"Projekt.exe": "C:\Windows\SysWOW64\gdi32.dll" geladen, Cannot find or open the PDB file
"Projekt.exe": "C:\Windows\SysWOW64\user32.dll" geladen, Cannot find or open the PDB file
"Projekt.exe": "C:\Windows\SysWOW64\lpk.dll" geladen, Cannot find or open the PDB file
"Projekt.exe": "C:\Windows\SysWOW64\usp10.dll" geladen, Cannot find or open the PDB file
"Projekt.exe": "C:\Windows\SysWOW64\winmm.dll" geladen, Cannot find or open the PDB file
"Projekt.exe": "D:\Admin\Documents\Visual Studio 2010\Projects\Projekt\Debug\SDL_image.dll" geladen, Die Binärdaten wurden nicht mit Debuginformationen erstellt.
"Projekt.exe": "D:\Admin\Documents\Visual Studio 2010\Projects\Projekt\Debug\SDL_ttf.dll" geladen, Die Binärdaten wurden nicht mit Debuginformationen erstellt.
"Projekt.exe": "D:\Admin\Documents\Visual Studio 2010\Projects\Projekt\Debug\libfreetype-6.dll" geladen, Die Binärdaten wurden nicht mit Debuginformationen erstellt.
"Projekt.exe": "D:\Admin\Documents\Visual Studio 2010\Projects\Projekt\Debug\zlib1.dll" geladen, Die Binärdaten wurden nicht mit Debuginformationen erstellt.
"Projekt.exe": "C:\Windows\SysWOW64\msvcp100d.dll" geladen, Symbole wurden geladen.
"Projekt.exe": "C:\Windows\SysWOW64\msvcr100d.dll" geladen, Symbole wurden geladen.
"Projekt.exe": "C:\Windows\SysWOW64\imm32.dll" geladen, Cannot find or open the PDB file
"Projekt.exe": "C:\Windows\SysWOW64\msctf.dll" geladen, Cannot find or open the PDB file
"Projekt.exe": "C:\Windows\SysWOW64\uxtheme.dll" geladen, Cannot find or open the PDB file
"Projekt.exe": "C:\Windows\SysWOW64\dwmapi.dll" geladen, Cannot find or open the PDB file
"Projekt.exe": "C:\Windows\SysWOW64\KBDUS.DLL" geladen, Cannot find or open the PDB file
"Projekt.exe": "C:\Windows\SysWOW64\KBDUS.DLL" entladen.
"Projekt.exe": "C:\Windows\SysWOW64\KBDGR.DLL" geladen, Cannot find or open the PDB file
"Projekt.exe": "C:\Windows\SysWOW64\KBDGR.DLL" entladen.
"Projekt.exe": "C:\Windows\SysWOW64\ole32.dll" geladen, Cannot find or open the PDB file
"Projekt.exe": "C:\Windows\SysWOW64\clbcatq.dll" geladen, Cannot find or open the PDB file
"Projekt.exe": "C:\Windows\SysWOW64\oleaut32.dll" geladen, Cannot find or open the PDB file
Eine Ausnahme (erste Chance) bei 0x6f4c2a9d in Projekt.exe: 0xC0000005: Zugriffsverletzung beim Lesen an Position 0xcccccccc.
Unbehandelte Ausnahme bei 0x6f4c2a9d in Projekt.exe: 0xC0000005: Zugriffsverletzung beim Lesen an Position 0xcccccccc.
Das Programm "[4856] Projekt.exe: Systemeigen" wurde mit Code -1073741819 (0xc0000005) beendet.
Das Programm startet aber dann kommt die Nachricht:
----------------------------------------------------------------------------------------------------------------------
Unbehandelte Ausnahme bei 0x6f4c2a9d in Projekt.exe: 0xC0000005: Zugriffsverletzung beim Lesen an Position 0xcccccccc.
----------------------------------------------------------------------------------------------------------------------
Hier ist der Quellcode ( um dieses Programm ging es schon mal hier im Forum im Artikel "Fehler bei SDL Anwendung" ):
|
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
|
// MAIN_CPP
#include "Framework.hpp"
#include "Game.hpp"
int main (int argc, char *argv[])
{
// Framework initialisieren
if (g_pFramework->Init (800, 600, 16, false) == false)
{
getchar ();
return (0);
}
// Neue Instanz des Spiels
CGame Game;
Game.Init ();
// Spiel laufen lassen. Diese Funktion läuft so lange,
// bis das Spiel geschlossen oder die Escape-Taste
// gedrückt wird
Game.Run ();
// Spiel beenden
Game.Quit ();
// Framework beenden
g_pFramework->Quit ();
g_pFramework->Del ();
exit (1);
return (0);
}
|
|
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
|
#ifndef FRAMEWORK_HPP
#define FRAMEWORK_HPP
#include <iostream>
#include <SDL.h>
#include <SDL_image.h>
#include <SDL_ttf.h>
#include "Singleton.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;}
SDL_Surface *m_pScreen; // Surface für den Screen
private:
Uint8 *m_pKeystate; // Array für aktuellen Tastaturstatus
};
#endif
|
|
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
|
// FRAMEWORK_CPP
#include "Framework.hpp"
// Init
//
// Aufgabe: Framework initialisieren
//
bool CFramework::Init (int ScreenWidth, int ScreenHeight,
int ColorDepth, bool bFullscreen)
{
// Alle Systeme der SDL initialisieren
if (SDL_Init (SDL_INIT_VIDEO | SDL_INIT_TIMER) == -1 )
{
cout << "SDL konnte nicht initialisiert werden!" << endl;
cout << "Fehlermeldung: " << SDL_GetError () << endl;
Quit ();
return (false);
}
// SDL mit dem Grafiksystem initialisieren.
if(SDL_Init(SDL_INIT_VIDEO) == -1)
{
cout << "SDL konnte nicht initialisiert werden!" << endl;
cout << "Fehlermeldung: " << SDL_GetError () << endl;
Quit ();
return (false);
}
// SDL_ttf initialisieren.
if(TTF_Init() == -1)
{
cout << "Konnte SDL_ttf nicht initialisieren! Fehler: " << TTF_GetError() << endl;
return (false);
}
// Vollbild oder Fenstermodus einstellen
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);
}
// Prüfen, ob alles funktioniert hat
if (m_pScreen == NULL)
{
cout << "Videomodus konnte nicht gesetzt werden!" << endl;
cout << "Fehlermeldung: " << SDL_GetError () << endl;
Quit ();
return (false);
}
// Nun setzen wir noch den Titel des Fensters.
SDL_WM_SetCaption("SDG_Engine 2.0 PreRelease", "SDG_Engine 2.0 PreRelease");
// Zeiger auf internes Array für Tastaturstatus ermitteln
m_pKeystate = SDL_GetKeyState (NULL);
// Alles ging glatt, also true zurückliefern
return (true);
} // Init
// Quit
//
// Aufgabe: Framework (SDL) beenden
//
void CFramework::Quit ()
{
// SDL beenden
SDL_Quit ();
} // Quit
// Update
//
// Aufgabe: Timer und Keyboardstatus updaten
//
void CFramework::Update ()
{
// Tastaturstatus ermitteln
SDL_PumpEvents ();
} // Update
// Keydown
//
// Aufgabe: Tastendruck abfragen
//
bool CFramework::KeyDown (int Key_ID)
{
// Prüfen, ob Taste gedrückt ist
return (m_pKeystate[Key_ID] ? true : false);
} // KeyDown
// Clear
//
// Aufgabe: Buffer löschen
//
void CFramework::Clear ()
{
// Buffer (Surface) mit Hintergrundfarbe füllen
SDL_FillRect (m_pScreen, NULL,
SDL_MapRGB (m_pScreen->format, 0, 0, 0));
} // Clear
// Flip
//
// Aufgabe: Surface umschalten (flippen)
//
void CFramework::Flip ()
{
// Surface umschalten
SDL_Flip (m_pScreen);
} // Flip
|
|
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
|
#ifndef GAME_HPP
#define GAME_HPP
#include <SDL.h>
#include <SDL_image.h>
#include "Framework.hpp"
#include "Singleton.hpp"
#define g_pGame CGame::Get()
class CGame : public TSingleton<CGame>
{
public:
// Konstruktor
CGame ();
// Memberfunktionen
void Run ();
void Quit ();
int Init ();
// Hier laden wir unsere Bilder mit SDL_image.
SDL_Surface* Background;
SDL_Surface* Player;
// Schriftart "FreeSans.ttf" laden.
TTF_Font* font;
SDL_Surface* text;
// SDL_Rect Variablen (Position)
SDL_Rect BackgroundPosition;
SDL_Rect PlayerPosition;
SDL_Rect textPosition;
private:
void ProcessEvents ();
void CheckCollisions ();
bool m_bGameRun; // Läuft das Spiel noch?
};
#endif
|
|
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
|
// GAME_CPP
#include "Game.hpp"
#include <iostream>
#include <windows.h>
using namespace std;
// Konstruktor
//
// Aufgabe: Allgemeine Initialisierungen
//
CGame::CGame ()
{
Background = IMG_Load("Data/Background.bmp");
Player = IMG_Load("Data/Player.bmp");
TTF_Font* font = TTF_OpenFont("FreeSans.ttf", 30);
} // Konstruktor
// Quit
//
// Aufgabe: Instanzen freigeben
//
void CGame::Quit ()
{
SDL_Quit ();
exit (1);
} // Quit
int CGame::Init ()
{
// Grafiken
if(!g_pGame->Background)
{
// Fehler!
cout << "Konnte das Bild nicht laden! Fehler: " << IMG_GetError() << endl;
return (false);
}
if(!g_pGame->Player)
{
// Fehler!
cout << "Konnte Bild nicht laden! Fehler: " << IMG_GetError() << endl;
return (false);
}
// Schriften
if(!font)
{
// Fehler!
cout << "Konnte Schriftart nicht laden! Fehler: " << TTF_GetError() << endl;
return (false);
}
// Hier wird die Position bestimmt
g_pGame->BackgroundPosition.x = 0;
g_pGame->BackgroundPosition.y = 0;
// Hier wird die Position bestimmt
g_pGame->PlayerPosition.x = 150;
g_pGame->PlayerPosition.y = 150;
textPosition.x = 10;
textPosition.y = 5;
// Einen Text zeichnen.
SDL_Color textColor = {255, 127, 31};
SDL_Surface* text = TTF_RenderText_Blended(font, "SDL_ttf funktioniert!", textColor);
return 0;
}
// Run
//
// Aufgabe: Hauptschleife des Spiels
//
void CGame::Run ()
{
// Spiel läuft
m_bGameRun = true;
// Hauptschleife des Spiels durchlaufen
//
while (m_bGameRun == true)
{
// Events bearbeiten
ProcessEvents ();
// Framework updaten und Buffer löschen
g_pFramework->Update ();
g_pFramework->Clear ();
// Colorkey einstellen
SDL_SetColorKey (Background, SDL_SRCCOLORKEY,
SDL_MapRGB (Background->format, 255, 0, 255) );
// Colorkey einstellen
SDL_SetColorKey (Player, SDL_SRCCOLORKEY,
SDL_MapRGB (Player->format, 255, 0, 255) );
// Hintergrund rendern
SDL_BlitSurface(Background, 0, g_pFramework->GetScreen (), &BackgroundPosition);
// Testbild rendern
SDL_BlitSurface(Player, 0, g_pFramework->GetScreen (), &PlayerPosition);
// Den Text ausgeben.
SDL_BlitSurface(text, 0, g_pFramework->GetScreen (), &textPosition);
// Kollisionen prüfen
CheckCollisions ();
// Buffer flippen
g_pFramework->Flip ();
}
} // Run
// ProcessEvents
//
// Aufgabe: Events bearbeiten
//
void CGame::ProcessEvents ()
{
SDL_Event Event;
// Gab es ein Event?
if (SDL_PollEvent (&Event))
{
// Ja, also schauen welches
switch (Event.type)
{
// Beenden?
case (SDL_QUIT):
{
m_bGameRun = false;
} break;
// Wurde eine Taste gedrückt?
case (SDL_KEYDOWN):
{
switch (Event.key.keysym.sym)
{
case (SDLK_RIGHT):
{
// Spieler nach Rechts
}
case (SDLK_ESCAPE):
{
// Ja, also Spiel beenden
m_bGameRun = false;
} break;
}
} break;
}
}
} // ProcessEvents
// CheckCollisions
//
// Aufgabe: Kollisionen prüfen
//
void CGame::CheckCollisions ( )
{
} // CheckCollision
|
|
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
|
#ifndef SINGLETON_HPP
#define SINGLETON_HPP
template <class T>
class TSingleton
{
protected:
// Membervariablen
static T *m_pSingleton; // Statisches Objekt
public:
// Memberfunktionen
// Destruktor
//
virtual ~TSingleton ()
{
}
// Get
//
// Aufgabe: Wenn nötig, statisches Objekt erzeugen und
// Zeiger darauf zurückgeben
//
inline static T* Get ()
{
// Existiert schon eine Instanz?
if (!m_pSingleton)
m_pSingleton = new T; // Nein, dann neue Instanz erzeugen
// Zeiger auf die Instanz zurückgeben
return (m_pSingleton);
} // Get
// Statisches Objekt freigeben
//
static void Del ()
{
// Gab es eine Instanz?
if (m_pSingleton)
{
delete (m_pSingleton); // Ja, dann freigeben
m_pSingleton = NULL; // und Zeiger auf NULL setzen
}
} // Del
};
// Die statische Variable erzeugen
//
template <class T>
T* TSingleton<T>::m_pSingleton = 0;
#endif
|
Danke für eure Hilfe schon mal im vor raus!