Plantage graphique le retour (qui n'est jamais parti d'ailleurs)

Résolu
Mastersam Messages postés 116 Date d'inscription dimanche 26 septembre 2004 Statut Membre Dernière intervention 13 février 2008 - 2 nov. 2004 à 16:14
Mastersam Messages postés 116 Date d'inscription dimanche 26 septembre 2004 Statut Membre Dernière intervention 13 février 2008 - 2 nov. 2004 à 22:26
Je relance un nouveau sujet car mon problème n'est toujours pas réglé après 3 semaines, il ne doit pas être bien méchant pour les expérimentés mais pour moi c'est le calvaire et je suis en train de me démotiver.

Mon projet contient une fenêtre principale et plusieurs fenêtres supplémentaires s'ouvrent lors de la sélection d'onglet dans le menu.

Si j'ouvre la fenêtre de détection du son, je lance la synchro, au bout de 2 minutes environ j'ai le droit à un plantage graphique, mes barres de titres de toutes les fenêtres me font n'importe quoi et les fenêtres elles-même ne se redessinent plus correctement.

Maintenant avec la fenêtre avec tous les potentiomètres après un certain nombre de manipulation des curseurs j'ai le même problème.

L'erreur survient au bout d'un certain nombre d'opération, elle n'est pas liée à une durée, si je ne fait rien avec les boutons ça ne plante pas, et pour le son si j'accélère le défilement du graphe et bien ça plante d'autant plus vite.

j'ai tout essayé, DeleteDC releaseDC , mettre mes variable hors de la fonction pour les creer qu'une fois, mettre mes fonctions au début pour ne pas les redéclarer mettre des return 0 à la place des break. Rien à faire ça plante toujours.

j'ai essayé aussi les options d'optimisation dans devcpp, compatibilité du code, thème xp, toujours pareil, ça plante.

J'ai pensé à quelque chose, Mon projet est un projet avec une fenêtre mère et des fenêtre suplémentaire, donc une sorte d'environnement multifenêtre. Est-ce qui y aurait quelquechose à configurer ou a changer, du style passer en MDI ou changer le type de fenêtre ?

Je comprends plus j'ai essayé tous les codes proposée dans le site pour l'affichage et rien faire ça plante toujours d'une façon ou d'une autre.

Même le double buffering scintille encore et plante aussi, et avec un timer pour le taux de rafraichissement ça marche pas non plus.

La source est br http://www.rc-bot.com/ST-Light/

Merci d'avance de m'aider un peu. J'ai vraiment pas envie d'abandonner, donnez-moi une nouvelle piste de recherche, ou l'erreur que j'ai faites, je demande pas forcemment la solution directe, mais de nouvelles idées sur le problème car j'en manque là.

http://www.rc-bot.com

4 réponses

ymca2003 Messages postés 2070 Date d'inscription mardi 22 avril 2003 Statut Membre Dernière intervention 3 juillet 2006 7
2 nov. 2004 à 17:58
tous les objets graphiques ne sont pas détruits car tu te sert de la même variable hp pour créer des HPEN mais tu ne fiat qu'un seul DeleteObject.

hp = CreatePen(PS_SOLID, 1, 0x003300AA);
SelectObject(hdcsound, hp);

...
hp = CreatePen(PS_SOLID, 1, 0x0055FFFF);
SelectObject(hdcsound, hp);

...
DeleteObject(hp)

=> seul le dernier HPEN est détruit et encore, il est resté dans un DC donc fuite de mémoire.

correction du 1er WM_PAINT :

case WM_PAINT:
 {
  HDC hdcsound;
   PAINTSTRUCT pssound;
   HPEN hp1, hp2, hp3, hp4;      
   HPEN holdp;
   HBRUSH hb;      // Fond du scope
  HBRUSH holdb;
   LOGBRUSH lb;     // Style de la brush
   rect.left = 0;
   rect.top = 0;
   rect.right = 310;
   rect.bottom = 67;
        
   // Structure pour la brush
   lb.lbStyle = BS_SOLID;    
   lb.lbColor = 0x00330000;
        
   // On recupere le DC de la fenetre
    hdcsound = BeginPaint(hwnd,&pssound);
       
    // Creation de BRUSH
    hb = CreateBrushIndirect(&lb);
    hodb = (HBRUSH) SelectObject(hdcsound, hb);
     
        // On dessine le fond du scope
        Rectangle(hdcsound, rect.left, rect.top, rect.right, rect.bottom);
        
        hp1 = CreatePen(PS_SOLID, 1, 0x00DD7700);
        holdp = (HPPEN)SelectObject(hdcsound, hp1);
        
        for(i=0; i<310; i++)
        {     
          MoveToEx(hdcsound, i,rect.bottom-(6*beat[i]), NULL);
          LineTo(hdcsound, i,rect.bottom-7);
          if(sound[i]>min){
          LineTo(hdcsound, i,rect.bottom-7-(((sound[i]-min)*60/(max-min))));
          }              
        }
        
        hp2 = CreatePen(PS_SOLID, 1, 0x00AA3300);
        SelectObject(hdcsound, hp2);
        
        if(moyenne<max)
        {       
          MoveToEx(hdcsound, 0,rect.bottom-7-((moyenne-min)*60/(max-min)), NULL);
          LineTo(hdcsound, 310,rect.bottom-7-((moyenne-min)*60/(max-min)));    
        }
        
        hp3 = CreatePen(PS_SOLID, 1, 0x003300AA);
        SelectObject(hdcsound, hp3);
        
        if(seuilreel<max)
        {if(seuilreel>min){       
          MoveToEx(hdcsound, 0,rect.bottom-7-((seuilreel-min)*60/(max-min)), NULL);
          LineTo(hdcsound, 310,rect.bottom-7-((seuilreel-min)*60/(max-min)));    
        }}
                        
        hp4 = CreatePen(PS_SOLID, 1, 0x0055FFFF);
        SelectObject(hdcsound, hp4);
        
        if(moyenne+limithi<max)
        {       
          MoveToEx(hdcsound, 0,rect.bottom-7-((moyenne+limithi-min)*60/(max-min)), NULL);
          LineTo(hdcsound, 310,rect.bottom-7-((moyenne+limithi-min)*60/(max-min)));  
        } 
        if(moyenne+limitlow<max)
        {       
          MoveToEx(hdcsound, 0,rect.bottom-7-((moyenne+limitlow-min)*60/(max-min)), NULL);
          LineTo(hdcsound, 310,rect.bottom-7-((moyenne+limitlow-min)*60/(max-min)));  
        }
          
       

        // Fin du dessin
SelectObject(hdcsound, holp);
SelectObject(hdcsound, holdb);

         DeleteObject(hp1);
         DeleteObject(hp2);
         DeleteObject(hp3);
         DeleteObject(hp4);

        DeleteObject(hb);
        EndPaint(hwnd,&pssound);
        
        return 0;

3
Mastersam Messages postés 116 Date d'inscription dimanche 26 septembre 2004 Statut Membre Dernière intervention 13 février 2008
2 nov. 2004 à 16:18
C'est bien ma vaine je sais même plus poster un lien,

celui là devrait marcher:
http://www.rc-bot.com/ST-Light/
0
ymca2003 Messages postés 2070 Date d'inscription mardi 22 avril 2003 Statut Membre Dernière intervention 3 juillet 2006 7
2 nov. 2004 à 18:01
2ème WM_PAINT:

      case WM_PAINT:
          {
          PAINTSTRUCT psdmx;
        hdc=BeginPaint(hwnd,&psdmx);	// obtient un handle de contexte de périphérique

HBITMAP holdbmp;

      BITMAP bmf;
      bitmapfaderDMX=(HBITMAP) LoadImage(g_hInst,"fader",IMAGE_BITMAP,0,0,LR_CREATEDIBSECTION); 
      hdcfaderDMX=CreateCompatibleDC(hdc); 
holdbmp = (HBITMAP)SelectObject(hdcfaderDMX,bitmapfaderDMX);
GetObject(bitmapfaderDMX,sizeof(bmf),&bmf);

          
 for(i=1; i<33; i+=1)
{
  BitBlt(hdc,i*31-23,21,bmf.bmWidth,bmf.bmHeight,hdcfaderDMX,0,0,SRCCOPY);  
         
 }
SelectObject(hdcfaderDMX, holdbmp);
 DeleteDC(hdcfaderDMX);       
DeleteObject(bitmapfaderDMX);
  EndPaint(hwnd, &psdmx);     
0
Mastersam Messages postés 116 Date d'inscription dimanche 26 septembre 2004 Statut Membre Dernière intervention 13 février 2008
2 nov. 2004 à 22:26
Merci ça fait trop plaisir de le voir marcher, ça va faire une bonne heure que ça tourne sans planter.

Je me suis même payé le luxe de rajouter un double buffering, en prenant compte de ces nouvelles concidérations.

Je pensais pas que l'objet n'était pas détruit si on en créait plusieurs sur le même (hp et non pas hp1,2 ...) et j'avais pas trop
compris comment on rechargeait les objets initiaux dans le DC.
C'était ça l'erreur.

Encore merci.

Je vais mettre le résultat du paint pour que ça puisse servir à d'autre:
case WM_PAINT:
   {      
        HDC hdcsound,hdcsoundtmp;
        PAINTSTRUCT pssound;
        HPEN hp1, hp2, hp3, hp4; 
        HPEN holdp;
        HBRUSH hb; // Fond du scope
        HBRUSH holdb;
        HBITMAP hOldBmp;
        HBITMAP hMemBmp;
        LOGBRUSH lb; // Style de la brush
        rect.left = 0;
        rect.top = 0;
        rect.right = 310;
        rect.bottom = 67;
        
        // Structure pour la brush
        lb.lbStyle = BS_SOLID; 
        lb.lbColor = 0x00330000;
        
        // On recupere le DC de la fenetre
        hdcsound = BeginPaint(hwnd,&pssound);
        hdcsoundtmp=CreateCompatibleDC(hdcsound);
        hMemBmp= CreateCompatibleBitmap(hdcsound, 310,67);
        hOldBmp= SelectObject(hdcsoundtmp, hMemBmp);
        // Creation de BRUSH
        hb = CreateBrushIndirect(&lb);
        holdb = (HBRUSH)SelectObject(hdcsoundtmp, hb);
        
        // On dessine le fond du scope
        Rectangle(hdcsoundtmp, rect.left, rect.top, rect.right, rect.bottom);
        
        hp1 = CreatePen(PS_SOLID, 1, 0x00DD7700);
        holdp = (HPEN)SelectObject(hdcsoundtmp, hp1);
        
        for(i=0; i<310; i++)
        { 
        MoveToEx(hdcsoundtmp, i,rect.bottom-(6*beat[i]), NULL);
        LineTo(hdcsoundtmp, i,rect.bottom-7);
        if(sound[i]>min){
        LineTo(hdcsoundtmp, i,rect.bottom-7-(((sound[i]-min)*60/(max-min))));
        } 
        }
        
        hp2 = CreatePen(PS_SOLID, 1, 0x00AA3300);
        SelectObject(hdcsoundtmp, hp2);
        
        if(moyenne<max)
        { 
        MoveToEx(hdcsoundtmp, 0,rect.bottom-7-((moyenne-min)*60/(max-min)), NULL);
        LineTo(hdcsoundtmp, 310,rect.bottom-7-((moyenne-min)*60/(max-min))); 
        }
        
        hp3 = CreatePen(PS_SOLID, 1, 0x003300AA);
        SelectObject(hdcsoundtmp, hp3);
        
        if(seuilreel<max)
        {if(seuilreel>min){ 
        MoveToEx(hdcsoundtmp, 0,rect.bottom-7-((seuilreel-min)*60/(max-min)), NULL);
        LineTo(hdcsoundtmp, 310,rect.bottom-7-((seuilreel-min)*60/(max-min))); 
        }}
        
        hp4 = CreatePen(PS_SOLID, 1, 0x0055FFFF);
        SelectObject(hdcsoundtmp, hp4);
        
        if(moyenne+limithi<max)
        { 
        MoveToEx(hdcsoundtmp, 0,rect.bottom-7-((moyenne+limithi-min)*60/(max-min)), NULL);
        LineTo(hdcsoundtmp, 310,rect.bottom-7-((moyenne+limithi-min)*60/(max-min))); 
        } 
        if(moyenne+limitlow<max)
        { 
        MoveToEx(hdcsoundtmp, 0,rect.bottom-7-((moyenne+limitlow-min)*60/(max-min)), NULL);
        LineTo(hdcsoundtmp, 310,rect.bottom-7-((moyenne+limitlow-min)*60/(max-min))); 
        }
        
        BitBlt(hdcsound,0,0,310,67,hdcsoundtmp,0,0,SRCCOPY);
        
        // Fin du dessin
        SelectObject(hdcsound, holdp);
        SelectObject(hdcsound, holdb);
        SelectObject(hdcsoundtmp, hOldBmp);
        DeleteObject(hMemBmp);
        DeleteDC(hdcsoundtmp);
        DeleteObject(hp1);
        DeleteObject(hp2);
        DeleteObject(hp3);
        DeleteObject(hp4);
        
        DeleteObject(hb);
        EndPaint(hwnd,&pssound);
        
        return 0;
      }



http://www.rc-bot.com
0
Rejoignez-nous