Moi non plus je ne vois rien de suspect avec la macro et je ne comprends pas pourquoi ça crash :
Code cpp : 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 #include "serialization.h" #define REGISTER_KEY(KEY, TYPE, TYPES...) \ struct KEY : public odfaeg::Serializer<TYPE, TYPES> { \ public : \ KEY () : odfaeg::Serializer<TYPE, TYPES>() {std::cout<<__LINE__<<std::endl;} \ void register_object (TYPE* object) { \ setObject(object); \ } \ TYPE* allocate_object(int index) { \ return sallocate(index); \ } \ int getTypeIndex () { \ return odfaeg::Serializer<TYPE, TYPES>::getIndex(); \ } \ template <typename Archive> \ void serialize_object (Archive & ar, int) { \ odfaeg::Serializer<TYPE, TYPES>::serialize(ar); \ } \ }; \ public : \ KEY key; \ typedef KEY KEYTYPE; \ static TYPE* allocate (int index) { \ static KEY aKey; \ return aKey.allocate_object(index); \ }
J'ai bien fait un ifndef pour éviter de redéfinir la macro si je la défini dans le main.
Code cpp : 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
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 #ifndef ODFAEG_BOUNDING_VOLUME_HPP #define ODFAEG_BOUNDING_VOLUME_HPP #include "../Math/vec4.h" #include <string> #include "../Core/serialization.cpp" #ifndef BVKEY #define BVKEY REGISTER_KEY(BVKEY, odfaeg::BoundingVolume, odfaeg::BoundingBox) #endif /** *\namespace odfaeg * the namespace of the Opensource Development Framework Adapted for Every Games. */ namespace odfaeg { /** * \file boundingVolume.h * \class BoudingVolume * \brief Manage a bounding volume for collision detection * \author Duroisin.L * \version 1.0 * \date 1/02/2014 * * Base class of all bouding volumes of the framework used for collision detection. * */ class BoundingVolume; class BoundingBox; class BoundingSphere; class BoundingPolyhedron; class BaseInterface { public : void addChild(BoundingVolume* bv) { children.push_back(bv); } std::vector<BoundingVolume*> getChildren() { return children; } std::vector<BoundingVolume*> children; }; template <typename T> class Interface : public BaseInterface { public : T /* const */ & data() /* const*/{return t_;} protected: Interface(T & t) : t_(t){ } /*const Interface<T>& operator= (const Interface<T>& other) { t_ = other.t_; return *this; }*/ virtual ~Interface(){} private: T & t_; }; class BoundingVolume : public BaseInterface { public : bool intersects(BaseInterface& other) { //if(static_cast<C&>(other)) { if (children.size() == 0 && other.children.size() == 0) { return onIntersects(static_cast<BoundingVolume&>(other)); } else if (children.size() == 0 && other.children.size() != 0) { for (unsigned int i = 0; i < other.children.size(); i++) { if (onIntersects(*static_cast<BoundingVolume&>(other).children[i])) return true; } } else { for (unsigned int i = 0; i < children.size(); i++) { if (other.children.size() == 0) { if (children[i]->onIntersects(static_cast<BoundingVolume&>(other))) return true; } else { for (unsigned j = 0; j < other.children.size(); j++) { if (children[i]->onIntersects(*static_cast<BoundingVolume&>(other).children[j])) return true; } } } } //} return false; } virtual bool onIntersects(BoundingVolume& other) { } template <typename T> bool intersects(Interface<T>* interface) { return interface->data().intersects(*this); } virtual Vec3f getPosition() { return Vec3f(0, 0, 0); } virtual Vec3f getSize() { return Vec3f(0, 0, 0); } virtual Vec3f getCenter() { return Vec3f(0, 0, 0); } virtual void move (Vec3f t) { } virtual BoundingVolume* clone () { return new BoundingVolume(*this); } const BoundingVolume& operator= (const BoundingVolume& other) { return *this; } template <typename Archive> void serialize(Archive & ar) { std::cout<<"Serialize bounding volume"<<std::endl; } void foo() {} virtual ~BoundingVolume() {} BVKEY }; } #endif // BOUNDING_AREAS
Bref j'ai mis des __LINE__ partout et ça crash à la ligne 35 :
Code cpp : 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 #define BVKEY REGISTER_KEY(BVKEY, odfaeg::BoundingVolume, odfaeg::BoundingBox, odfaeg::BoundingSphere) #include "odfaeg/Graphics/renderWindow.h" #include "odfaeg/Graphics/2D/tile.h" int main(int argc, char* args[]) { std::cout<<__LINE__<<std::endl; sf::VideoMode mode(800, 600); std::cout<<__LINE__<<std::endl; sf::ContextSettings settings(0, 0, 4, 3, 0); std::cout<<__LINE__<<std::endl; odfaeg::RenderWindow window(mode, "test", sf::Style::Default, settings); std::cout<<__LINE__<<std::endl; odfaeg::Texture tex; std::cout<<__LINE__<<std::endl; tex.loadFromFile("tilesets/herbe.png"); std::cout<<__LINE__<<std::endl; odfaeg::g2d::Entity* tile = new odfaeg::g2d::Tile (&tex, odfaeg::Vec3f(0, 0, 0), odfaeg::Vec3f(100, 50, 0), sf::IntRect(0, 0, 100, 50)); std::cout<<__LINE__<<std::endl; while (window.isOpen()) { std::cout<<__LINE__<<std::endl; sf::Event event; std::cout<<__LINE__<<std::endl; while(window.pollEvent(event)) { std::cout<<__LINE__<<std::endl; if (event.type == sf::Event::Closed) { std::cout<<__LINE__<<std::endl; window.close(); std::cout<<__LINE__<<std::endl; } std::cout<<__LINE__<<std::endl; } std::cout<<__LINE__<<std::endl; window.clear(); std::cout<<__LINE__<<std::endl; window.draw(*tile); std::cout<<__LINE__<<std::endl; window.display(); std::cout<<__LINE__<<std::endl; } delete tile; return 0; }
Et donc au moment du draw, je ne comprend pas pourquoi ça crash là mais quand je ne redéfini pas la macro dans le main, ça ne crash pas, donc le problème vient sûrement de la macro mais je ne vois pas ou.
Partager