Bonjour à tous,

J'ai une classe template qui me permet de construire des graph simples:
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
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
 
/*
 * sNode.h
 *
 *  Created on: 17 févr. 2011
 *      Author: seeme
 */
 
#ifndef SNODE_H_
#define SNODE_H_
 
#include <iterator>
#include <list>
#include "../../LogManager/Log.hpp"
#include <boost/serialization/list.hpp>
 
template <class T>
class sNode {
public:
	sNode<T>(){}
 
	sNode<T>(T value):m_value(value){};
 
	sNode<T>(T val, std::list<T> children):m_value(val), m_children(children){};
 
	void setValue(T value){
		m_value = value;
	}
 
	T getValue(){
		return m_value;
	}
 
	void addChild(sNode<T>* child){
		m_children.push_back(child);
	}
 
	std::list<sNode<T> > getChildren(){
		return m_children;
	}
 
	void setChildren(std::list<sNode<T> > children){
		m_children.clear();
		m_children = children;
	}
 
	void appendChildren(std::list<sNode<T> > children){
		m_children.insert(children);
	}
 
	int numberOfChildren(){
		return m_children.size();
	}
 
	friend std::ostream& operator<<(std::ostream& out, const sNode<T>& node){
		node.print(out);
		return out;
	}
 
	virtual void print(std::ostream& o) const {
		o << "<" << m_value << ">\n";
	}
 
	void display(int depth = 1){
		typedef typename std::list<sNode<T>* >::const_iterator Iterator;
		Iterator iter= m_children.begin();
		int curDepth = depth;
 
		print(std::cout);
		//std::cout << curDepth;
		std::string space;
		for(int i = 0; i < curDepth-1; ++i)
						space.append("\t");
		while(iter != m_children.end()){
			std::cout << space << "\t";
			((sNode) **iter).display(curDepth+1);
			iter++;
		}
		std::cout << space << "</" << m_value << ">" << std::endl;
	}
 
	~sNode<T>(){
		typedef typename std::list<sNode<T>* >::const_iterator Iterator;
		Iterator iter= m_children.begin();
		while(iter != m_children.end()){
			delete *iter;
			iter++;
		}
	}
 
	//Serialization
	template<class Archive>
	void serialize(Archive& ar, const unsigned int version){
		Log::d("SerializationGraph") << "Serializing " << m_value;
		ar & m_value;
	}
 
protected:
	T m_value;
	std::list<sNode<T>* > m_children;
};
 
#endif /* SNODE_H_ */
La géométrie de mon monde est constitué de classe héritées de AbstractEntity:

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
 
/*
 * AbstractEntity.h
 *
 *  Created on: 17 févr. 2011
 *      Author: seeme
 */
 
#ifndef ABSTRACTENTITY_H_
#define ABSTRACTENTITY_H_
 
#include <ostream>
#include "../../LogManager/Log.hpp"
#include <boost/serialization/access.hpp>
#include <boost/serialization/base_object.hpp>
 
 
class AbstractEntity {
	friend class boost::serialization::access;
 
 
public:
	AbstractEntity();
	virtual ~AbstractEntity();
 
 
	friend std::ostream& operator<<(std::ostream& out, const AbstractEntity& ent){
		ent.print(out);
		return out;
	}
 
	virtual void print(std::ostream& o) const {
		o << "plop entity";
	}
 
private:
	//Serialization
	template<class Archive>
	void serialize(Archive& ar, const unsigned int version){
		//ar & m_modelHandle & m_position & m_rotation & m_scale;
	}
};
 
#endif /* ABSTRACTENTITY_H_ */
Voici un exemple avec une entité fixe:

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
 
/*
 * StaticModelEntity.h
 *
 *  Created on: 17 févr. 2011
 *      Author: seeme
 */
 
#ifndef STATICMODELENTITY_H_
#define STATICMODELENTITY_H_
 
#include "../../Memory/ResCache.h"
#include "../../Tools/Geometry/Vect3.h"
#include "AbstractEntity.h"
 
class StaticModelEntity: public AbstractEntity {
public:
	StaticModelEntity(HANDLE hdl, Vect3<int> position, Vect3<int> rotation, Vect3<int> scale):m_modelHandle(hdl), m_position(position), m_scale(scale){};
	StaticModelEntity();
	virtual ~StaticModelEntity();
 
	//Serialization
	template<class Archive>
	void serialize(Archive& ar, const unsigned int version){
 
		ar & boost::serialization::base_object<AbstractEntity>(*this);
		ar & m_modelHandle & m_position & m_rotation & m_scale;
	}
 
protected:
	HANDLE m_modelHandle;
	Vect3<int> m_position;
	Vect3<int> m_rotation;
	Vect3<int> m_scale;
};
 
#endif /* STATICMODELENTITY_H_ */

Mon monde est donc un graph de pointeur vers AbstractEntity:
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
 
/*
 * Level.h
 *
 *  Created on: 15 févr. 2011
 *      Author: seeme
 */
 
#ifndef LEVEL_H_
#define LEVEL_H_
 
#include <list>
#include <boost/archive/text_oarchive.hpp>
#include <boost/serialization/serialization.hpp>
#include "../../Scene/Entity/AbstractEntity.h"
#include "../../Tools/Graph/sNode.h"
 
class Level: public Resource{
public:
	Level(std::string name, std::string path);
	Level();
	virtual ~Level();
 
	//Serialization
	template<class Archive>
	void serialize(Archive& ar, const unsigned int version){
		ar & m_models & m_sceneGraph;
	}
 
private:
	std::list<HANDLE> m_models;
	sNode<AbstractEntity*> m_sceneGraph;
};
 
#endif /* LEVEL_H_ */
(Les HANDLE sont de simple std::string).

Malheureusement, quand je serialize mon Level, les handles sont bien sauvegardés, mais j'ai un null pointer exception au moment où il essaye d'enregistrer sNode<AbstractEntity*>::m_value.

Je bloque dessus depuis 2 jours, j'aurais besoin d'un oeuil neuf là dessus..

Le problème vient très probablement de l'héritage, mais je n'arrive pas à mettre le doigt dessus...


Merci d'avance...