Bonjour tout le monde,
J'ai un souci avec un de mes projets, je dispose d'une application avec 2 threads, ( le main et le rendu opengl).
Ceci fonctionne bien, sauf vous vous doutez bien, un truc!
Alors pour commencer j'ai une classe qui manage mon thread de rendu avec une structure définissant le paramètre de ce thread.
Platform est ici une classe Win32 qui créer/ouvre la fenêtre etc...
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 class RenderingThread { /* ........... */ template<typename Platform> struct Param { const Platform &m_platform; const CEL::WindowConfiguration& m_windowConfiguration; RenderingThread<GraphicAPI,Platform>& m_renderThread; Param( const Platform & _platform, const CEL::WindowConfiguration& _windowConfiguration, RenderingThread<GraphicAPI,Platform>& _renderThread) :m_platform(_platform), m_windowConfiguration(_windowConfiguration), m_renderThread(_renderThread) {} }; /* ........... */ }
CEL::WindowConfiguration est une structure de ce type :
Et RenderingThread<GraphicAPI,Platform> est tout simplement la classe qui va me servir a faire des appels des rendus.
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 struct WindowConfiguration { Int m_height; Int m_width; Int m_posX; Int m_posY; Bool m_fullscreen; Bool m_vSync; String m_appName; Int m_FPS; Int m_glBuffer; Int m_glRedBits; Int m_glGreenBits; Int m_glBlueBits; Int m_glAlphaBits; Int m_glDepthBits; Int m_glStencilBits;
A la création du thread:
Je créer la structure sur le heap et créer le thread.
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2 RenderingThread<GraphicAPI,Platform>::Param<Platform> *param = CELNew RenderingThread<GraphicAPI,Platform>::Param<Platform>(_platform,_windowConfiguration,*this); m_renderThread = Management::ThreadManager::Get().CreateThread(MainRendering<GraphicAPI,Platform>,param);
Dans ma Routine du thread:
Je récupère le paramètre de type RenderingThread:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7 template<typename GraphicAPI,typename Platform> static CELThreadRoutine MainRendering(Void *param) { RenderingThread::Param<Platform> *renderParam = reinterpret_cast<RenderingThread::Param<Platform>*>(param); RenderingThread<GraphicAPI,Platform>& renderThread(renderParam->m_renderThread); if(renderThread.m_interfacer.Init(PlatformInterface<Platform,GraphicAPI>::GetParam(renderParam->m_platform),renderParam->m_windowConfiguration)== CEL::FctError) return FctError;aram<Platform>*
Lorsque je passe mon paramètre renderParam->m_windowConfiguration à m_interfacer.Init par référence, lors de l'appelle d'une fonctiondans la méthode Init, le paramètre _windowConfiguration devient n'importe quoi, à savoir des valeurs -8979032, et des <Bad Ptr>... Sachant que dans cette méthode ce paramètre n'est jamais utilisé. J'ai remarqué que ce problème n'est pas présent dans cette fonction si on utilise _windowConfiguration par copie. Mais dans ce cas la c'est dans la fonction appelante ( Routine du thread ) que la structure se retrouve avec ces valeurs.
Code : Sélectionner tout - Visualiser dans une fenêtre à part ChoosePixelFormat(reinterpret_cast<HDC>(_displayID), &m_pixelFormatDescription);
J'avoue ne pas comprendre ce bord*l.
Si une personne à le courage et la patience de trouver une possible solution
Merci
Partager