Bonjour,

J'ai un problème de pointeur je pense. Et avec mon niveau moyen en C++, je n'arrive pas à trouver d'où viens le problème.

Donc j'ai une classe InputManager qui gère la gestion du clavier dans une application que je développe. C'est une classe de type Singleton.
Je créer mon application une première fois avec cette classe et tout marche impeccable.
Le problème vient ensuite. J'ai besoin de TOUT détruire (y compris l'InputManager) pour recréer une fenêtre quand l'utilisateur choisi une nouvelle résolution de jeu ou des trucs du genre.
Donc je détruit le pointeur sur mon InputManager, et quand je le relance la fonction addKeyListener, mon application plante sur mKeyListener.find(instancename).

J'espère que vous pourrez m'aider, car je nage dans la farine là ...

Merci de votre aide, ci joint la classe InputManager.

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
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
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
#include "InputManager.h"
 
InputManager *InputManager::mInputManager=NULL;
 
InputManager::InputManager( void ) : mMouse( 0 ), mKeyboard( 0 ), mInputSystem( 0 ) 
{
}
 
InputManager::~InputManager( void ) 
{
    if( mInputSystem ) 
	{
        if( mMouse ) 
		{
            mInputSystem->destroyInputObject( mMouse );
            mMouse = 0;
        }
 
        if( mKeyboard ) 
		{
            mInputSystem->destroyInputObject( mKeyboard );
            mKeyboard = 0;
        }
 
        OIS::InputManager::destroyInputSystem(mInputSystem);
        mInputSystem = 0;
 
	mKeyListeners.clear();
        mMouseListeners.clear();
    }
}
 
void InputManager::initialise( Ogre::RenderWindow *renderWindow ) 
{
    if( !mInputSystem ) 
	{
        // Setup basic variables
        OIS::ParamList paramList;    
        size_t windowHnd = 0;
        std::ostringstream windowHndStr;
 
        // Get window handle
        renderWindow->getCustomAttribute( "WINDOW", &windowHnd );
 
        // Fill parameter list
        windowHndStr << windowHnd;
        paramList.insert( std::make_pair( std::string( "WINDOW" ), windowHndStr.str() ) );
		paramList.insert(std::make_pair(std::string("w32_mouse"), std::string("DISCL_FOREGROUND" )));
		paramList.insert(std::make_pair(std::string("w32_mouse"), std::string("DISCL_NONEXCLUSIVE")));
 
        // Create inputsystem
        mInputSystem = OIS::InputManager::createInputSystem( paramList );
 
        mKeyboard = static_cast<OIS::Keyboard*>( mInputSystem->createInputObject( OIS::OISKeyboard, true ) );
        mKeyboard->setEventCallback( this );
        mMouse = static_cast<OIS::Mouse*>( mInputSystem->createInputObject( OIS::OISMouse, true ) );
        mMouse->setEventCallback( this );
 
        // Get window size
        unsigned int width, height, depth;
        int left, top;
        renderWindow->getMetrics( width, height, depth, left, top );
 
        // Set mouse region
        this->setWindowExtents( width, height );
    }
}
 
void InputManager::capture( void ) 
{
    // Need to capture / update each device every frame
    if( mMouse )	mMouse->capture();
    if( mKeyboard ) mKeyboard->capture();
}
 
void InputManager::addKeyListener( OIS::KeyListener *keyListener, const std::string& instanceName ) 
{
    if( mKeyboard ) 
	{
        // Check for duplicate items
        itKeyListener = mKeyListeners.find( instanceName );
 
        if( itKeyListener == mKeyListeners.end() )	mKeyListeners[ instanceName ] = keyListener;
		else {	/* Duplicate Item */	}
    }
}
 
void InputManager::addMouseListener( OIS::MouseListener *mouseListener, const std::string& instanceName ) 
{
    if( mMouse ) 
	{
        // Check for duplicate items
        itMouseListener = mMouseListeners.find( instanceName );
        if( itMouseListener == mMouseListeners.end() )	mMouseListeners[ instanceName ] = mouseListener;
        else {	/* Duplicate Item */	}
    }
}
 
void InputManager::removeKeyListener( const std::string& instanceName ) 
{
    // Check if item exists
    itKeyListener = mKeyListeners.find( instanceName );
    if( itKeyListener != mKeyListeners.end() ) {
        mKeyListeners.erase( itKeyListener );
    }
    else {
        // Doesn't Exist
    }
}
 
void InputManager::removeMouseListener( const std::string& instanceName ) 
{
    // Check if item exists
    itMouseListener = mMouseListeners.find( instanceName );
    if( itMouseListener != mMouseListeners.end() )	mMouseListeners.erase( itMouseListener );
    else 
	{
        // Doesn't Exist
    }
}
 
void InputManager::removeKeyListener( OIS::KeyListener *keyListener ) 
{
    itKeyListener    = mKeyListeners.begin();
    itKeyListenerEnd = mKeyListeners.end();
    for(; itKeyListener != itKeyListenerEnd; ++itKeyListener ) {
        if( itKeyListener->second == keyListener ) {
            mKeyListeners.erase( itKeyListener );
            break;
        }
    }
}
 
void InputManager::removeMouseListener( OIS::MouseListener *mouseListener )
{
    itMouseListener    = mMouseListeners.begin();
    itMouseListenerEnd = mMouseListeners.end();
    for(; itMouseListener != itMouseListenerEnd; ++itMouseListener ) {
        if( itMouseListener->second == mouseListener ) {
            mMouseListeners.erase( itMouseListener );
            break;
        }
    }
}
 
void InputManager::removeAllListeners( void ) 
{
    mKeyListeners.clear();
    mMouseListeners.clear();
}
 
void InputManager::removeAllKeyListeners( void ) 
{
    mKeyListeners.clear();
}
 
void InputManager::removeAllMouseListeners( void ) 
{
    mMouseListeners.clear();
}
 
void InputManager::setWindowExtents( int width, int height ) 
{
    // Set mouse region (if window resizes, we should alter this to reflect as well)
    const OIS::MouseState &mouseState = mMouse->getMouseState();
    mouseState.width  = width;
    mouseState.height = height;
}
 
OIS::Mouse* InputManager::getMouse( void ) 
{
    return mMouse;
}
 
OIS::Keyboard* InputManager::getKeyboard( void ) 
{
    return mKeyboard;
}
 
bool InputManager::keyPressed( const OIS::KeyEvent &e ) {
    itKeyListener    = mKeyListeners.begin();
    itKeyListenerEnd = mKeyListeners.end();
    for(; itKeyListener != itKeyListenerEnd; ++itKeyListener ) {
        itKeyListener->second->keyPressed( e );
    }
 
    return true;
}
 
bool InputManager::keyReleased( const OIS::KeyEvent &e ) {
    itKeyListener    = mKeyListeners.begin();
    itKeyListenerEnd = mKeyListeners.end();
    for(; itKeyListener != itKeyListenerEnd; ++itKeyListener ) {
        itKeyListener->second->keyReleased( e );
    }
 
    return true;
}
 
bool InputManager::mouseMoved( const OIS::MouseEvent &e ) {
    itMouseListener    = mMouseListeners.begin();
    itMouseListenerEnd = mMouseListeners.end();
    for(; itMouseListener != itMouseListenerEnd; ++itMouseListener ) {
        itMouseListener->second->mouseMoved( e );
    }
 
    return true;
}
 
bool InputManager::mousePressed( const OIS::MouseEvent &e, OIS::MouseButtonID id ) {
    itMouseListener    = mMouseListeners.begin();
    itMouseListenerEnd = mMouseListeners.end();
    for(; itMouseListener != itMouseListenerEnd; ++itMouseListener ) {
        itMouseListener->second->mousePressed( e, id );
    }
 
    return true;
}
 
bool InputManager::mouseReleased( const OIS::MouseEvent &e, OIS::MouseButtonID id ) {
    itMouseListener    = mMouseListeners.begin();
    itMouseListenerEnd = mMouseListeners.end();
    for(; itMouseListener != itMouseListenerEnd; ++itMouseListener ) {
        itMouseListener->second->mouseReleased( e, id );
    }
 
    return true;
}
 
InputManager* InputManager::getSingletonPtr( void ) {
    if( !mInputManager ) {
        mInputManager = new InputManager();
    }
 
    return mInputManager;
}

Pour creer mon inputManager, je fais :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
mInputMgr = InputManager::getSingletonPtr();
mInputMgr->initialise( mRenderWindow );
mInputMgr->addKeyListener( this, "GameManager" );
mInputMgr->addMouseListener( this, "GameManager" );
Pour le détruire, je fais :