Ich habe ein Problem mit folgendem Code:
Dieses Programm stürzt bei der Zeile 62 ab.
|
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
|
#include <SFML/Graphics.hpp>
class B
{
private:
sf::RenderWindow *App;
sf::String Text;
public:
B() {}
void Load(sf::RenderWindow*, sf::String);
void Draw();
};
class A
{
private:
sf::RenderWindow *App;
B B1;
public:
A(sf::RenderWindow*);
void Draw();
};
int main()
{
sf::RenderWindow App(sf::VideoMode(800, 600), "Test");
A A1(&App);
while (App.IsOpened())
{
sf::Event Event;
while (App.GetEvent(Event))
{
if (Event.Type == sf::Event::Closed)
App.Close();
}
App.Clear();
A1.Draw();
App.Display();
}
return EXIT_SUCCESS;
}
void B::Load(sf::RenderWindow *_App, sf::String _Text)
{
App = _App;
Text = _Text;
}
void B::Draw()
{
App->Draw(sf::Shape::Line(0, 0, 100, 100, 5, sf::Color::Red)); //Diese Zeile funktioniert
App->Draw(Text); //Bei dieser Zeile stürzt das Programm ab
}
A::A(sf::RenderWindow *_App)
{
App = _App;
sf::Font Font1;
Font1.LoadFromFile("Arial.ttf");
B1.Load(App, sf::String("Test Test", Font1, 20));
}
void A::Draw()
{
B1.Draw();
}
|
Wenn ich in der Draw() Funktion die Schriftart nochmal lade stürzt das Programm nicht ab:
|
C-/C++-Quelltext
|
1
2
3
4
5
6
7
8
9
10
|
void B::Draw()
{
App->Draw(sf::Shape::Line(0, 0, 100, 100, 5, sf::Color::Red)); //Diese Zeile funktioniert
sf::Font Font1;
Font1.LoadFromFile("Arial.ttf");
Text.LoadFont(Font1);
App->Draw(Text); //Jetzt stürtzt das Programm nicht mehr ab
}
|
Bei diesem Beispiel wird B1 in der main geladen, das Programm stürzt nicht ab:
|
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
|
#include <SFML/Graphics.hpp>
class B
{
private:
sf::RenderWindow *App;
sf::String Text;
public:
B() {}
void Load(sf::RenderWindow*, sf::String);
void Draw();
};
int main()
{
sf::RenderWindow App(sf::VideoMode(800, 600), "Test");
sf::Font Font1;
Font1.LoadFromFile("Arial.ttf");
B B1;
B1.Load(&App, sf::String("Test Test", Font1, 20));
while (App.IsOpened())
{
sf::Event Event;
while (App.GetEvent(Event))
{
if (Event.Type == sf::Event::Closed)
App.Close();
}
App.Clear();
B1.Draw();
App.Display();
}
return EXIT_SUCCESS;
}
void B::Load(sf::RenderWindow *_App, sf::String _Text)
{
App = _App;
Text = _Text;
}
void B::Draw()
{
App->Draw(sf::Shape::Line(0, 0, 100, 100, 5, sf::Color::Red));
App->Draw(Text);
}
|
Ich versteh einfach nicht was da falsch läuft.