IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Langage C++ Discussion :

Inclusion de code source dans différents fichiers d'une bibliothèque en compilation. (Comment faire ?)


Sujet :

Langage C++

  1. #1
    Invité
    Invité(e)
    Par défaut Inclusion de code source dans différents fichiers d'une bibliothèque en compilation. (Comment faire ?)
    Salut.

    En fait je voudrais faire ceci : remplacer du code source en compilation dans différent fichiers à l'aide d'une macro, par exemple j'ai ce fichier ici que j'appelle code.h

    Code cpp : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
     
    #include "serializer.h"
    #define THECODE(CLASSNAME, BASE, DERIVED...) \
    struct CLASSNAME : public Serializer<BASE, DERIVED>  { \
      //Définition ici.
    }; \
    CLASSNAME obj

    Et ce fichier ci que je vais appeler implémentation.h

    Code cpp : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
     
    #include "code.h"
    #ifndef KEY 
    #define KEY GETCODE(DEFAULTNAME, DEFAULTBASE, DEFAULTDERIVED)
    #endif
    class EClass {
    //Défintion de la classe ici.
    KEY
    };

    Et je veux inclure le code qui se trouve dans le fichier code.h, dans la classe du fichier implementation.h afin que EClass contienne l'implémentation de la classe et un objet de la classe dans la macro.

    Ce code est dans une bibliothèque et je donne des paramètres par défaut à la macro pour définir le code à générer au cas ou la macro n'est pas redéfinie en dehors de la librairie.
    Jusque là pas de problème.

    Le problème survient ici :
    Je possède une troisième classe qui utilise pointeur sur un objet de type EClass comme ceci : (Cet objet est une entité graphique que je veux dessiner et EClass n'est rien d'autre qu'un pointeur vers un volume de collision)
    Code cpp : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
     
    class DClass {   
          public :
          //Definition de la classe ici.
          EClass* ptr;
    };

    Le problème est que lorsque je veux redéfinir la macro qui inclue le code généré en compilation en dehors de la bibliothèque, j'ai un crash lors du dessin et le pointeur sur l'objet EClass est modifié. (c'est à dire que, par exemple, si il était null, celui-ci contient une adresse)

    Je pense que c'est parce que le code du fichier.h de la bibliothèque, ne correspond plus avec le code contenu dans le fichier .a de la bibliothèque.

    Bref je ne vois pas très bien ce que je devrais faire pour régler le problème à part peut être faire une bibliothèque "header only". ?

    Mais je ne suis pas sûr que ça va fonctionner.
    Dernière modification par Neckara ; 21/08/2014 à 11h50. Motif: librarie -> bibliothèque

  2. #2
    Membre émérite
    Avatar de skeud
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Juin 2011
    Messages
    1 091
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 34
    Localisation : France, Loire Atlantique (Pays de la Loire)

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Juin 2011
    Messages : 1 091
    Points : 2 724
    Points
    2 724
    Billets dans le blog
    1
    Par défaut
    Pour l'instant tu ne parle que de .h

    Les define sont valable dans tout le code qui suit la définition.

    Normalement, ces define ne devrait pas intervenir dans le code cpp de ta biblio, car il est utilisé en dehors, je me trompe?

    L'erreur que tu obtiens ne serait pas du à un oubli d'initialisation de variable?
    Pas de solution, pas de probleme

    Une réponse utile (ou +1) ->
    Une réponse inutile ou pas d'accord -> et expliquer pourquoi
    Une réponse à votre question


  3. #3
    Invité
    Invité(e)
    Par défaut
    A vrai dire je ne sais pas, le débugueur ne me donne pas beaucoup d'information à ce sujet, je n'ai pas cette erreur quand je ne redéfini pas la macro, ce code ne crash pas.

    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
     
    #include "odfaeg/Graphics/renderWindow.h"
    #include "glCheck.h"
    #include "odfaeg/Graphics/window.h"
    #include <fstream>
    #include "odfaeg/Core/archive.h"
    #include "odfaeg/Graphics/2D/tile.h"
    #include <functional>
    int main(int argc, char* args[])
    {
        sf::VideoMode mode(800, 600);
        sf::ContextSettings settings(0, 0, 4, 3, 0);
        odfaeg::RenderWindow window(mode, "test", sf::Style::Default, settings);
        odfaeg::Texture tex;
        tex.loadFromFile("tilesets/herbe.png");   
        std::ostringstream oss;
        std::string text = "Ceci est un texte.";
        std::ofstream ofss("FichierDeSerialization.tex");
        {
            odfaeg::OTextArchive oa(ofss);
            oa(tex);
           // oa<<ofss;
        }
        ofss.close();
        std::istringstream iss;
        std::ifstream ifss("FichierDeSerialization.tex");
        {
            odfaeg::ITextArchive ia(ifss);
            ia(tex);
            //ia>>ifss;
        }
        ifss.close();
        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<<tile->getCollisionVolume()<<std::endl;
        while (window.isOpen()) {
            sf::Event event;
            while(window.pollEvent(event)) {
                if (event.type == sf::Event::Closed) {
                   window.close();
                }
            }
            window.clear();
            window.draw(*tile);
            window.display();
     
        }  
        delete tile;
     
     
        odfaeg::BoundingVolume* b1 = new odfaeg::BoundingSphere(odfaeg::Vec3f(0, 0, 0), 100);
        odfaeg::BoundingVolume* b2;
        std::ofstream ofs("FichierDeSerialisation");
        {
            odfaeg::OTextArchive oa(ofs);
            oa(b1);
        }
        ofs.close();
     
        std::ifstream ifs("FichierDeSerialisation");
        {
            odfaeg::ITextArchive ia(ifs);
            ia(&b2);
        }
        std::cout<<static_cast<odfaeg::BoundingSphere*>(b2)->getCenter()<<" "<<static_cast<odfaeg::BoundingSphere*>(b2)->getRadius()<<std::endl;
        ifs.close();
        return 0;
    Tandis que celui-ci crash :

    Code cpp : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
     
    #define BVKEY REGISTER_KEY(BOUNDINGVOLUMKEY, odfaeg::BoundingVolume, odfaeg::BoundingBox, odfaeg::BoundingSphere)

    La macro est définie dans le fichier main, avant tout les include que je fais.

    Bref normalement la déclaration de la classe ne devrait pas influer sur le .cpp comme tu dis, cependant :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
     
    #0 ??	?? () (??:??)
    #1 0x4300ef	draw(states=..., drawable=..., this=0x7ffffffdd4b8) (/usr/local/include/odfaeg/Graphics/renderTarget.h:30)
    #2 ??	main (argc=<optimized out>, args=<optimized out>) (/home/laurent/Développement/Projets-c++/ODFAEG-DEMO/main.cpp:48)
    En imprimant les adresse pourtant j'en ai bien une adresse pour chaque objet donc c'est au moment de l'appelle de la fonction dans la librairie que ça crash et je ne comprend pas très bien pourquoi. :o

  4. #4
    Membre émérite
    Avatar de skeud
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Juin 2011
    Messages
    1 091
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 34
    Localisation : France, Loire Atlantique (Pays de la Loire)

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Juin 2011
    Messages : 1 091
    Points : 2 724
    Points
    2 724
    Billets dans le blog
    1
    Par défaut
    Donc si je comprends bien:

    Compilation ok, et au runtime ça plante?

    Essaye de passer un coup de valgrind ou tout du moins un truc pour regarder tes fuite mémoire, je suis sur que tu as un petit soucis de mémoire à un endroit .

    Si tu pouvais posté en meme temps la sortie complete de ton application, ça serait cool .

    Rajoute aussi un peu de debug pour savoir exactement l'endroit ou ça plante .
    Pas de solution, pas de probleme

    Une réponse utile (ou +1) ->
    Une réponse inutile ou pas d'accord -> et expliquer pourquoi
    Une réponse à votre question


  5. #5
    Invité
    Invité(e)
    Par défaut
    Re, en effet je pense que le problème vient plutôt de la mémoire, je ne vois pas en quoi le fait de changer la définition d'une classe avec une macro, viendrait modifier le pointeur de l'objet sur la classe.

    Valgrind me sors en effet des erreurs mémoire mais je n'arrive pas à poster le fichier ici. (C'est un fichier xml)

    Je ne comprend pas très bien les messages dans ce fichier mais j'ai des messages du genre :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
     
    Leak_PossiblyLost
    9 bytes in 1 blocks are possibly lost in loss record 55 of 1,813
    Rajoute aussi un peu de debug pour savoir exactement l'endroit ou ça plante .
    Heu, comment faire cela ?
    Toute ma librairie est compilée en mode débug là..., ou bien alors c'est dans une dépendance utilisée par ma librairie mais ça je n'ai pas de contrôle là dessus. :/

    La sortie me dit juste Erreur de segmentation mais sans vraiment me donner plus d'information.

  6. #6
    Membre émérite
    Avatar de skeud
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Juin 2011
    Messages
    1 091
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 34
    Localisation : France, Loire Atlantique (Pays de la Loire)

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Juin 2011
    Messages : 1 091
    Points : 2 724
    Points
    2 724
    Billets dans le blog
    1
    Par défaut
    Quand tu modifie ton .h et que tu recompile, tu va modifier ton binaire, binaire qui contient tes variables. Il suffit que tu es un debordement de mémoire qui ne se voit pas trop pour que dans certains cas ça fonctionne et d'autre non.

    Le mieux:
    _ compile avec une option -g (ou -ggdb3)
    _ lance valgrind sur ton programme
    _ recherche les invalid write (ou read) qui correspondent à ton code
    _ regarde la ligne dans ton code.
    _ identifie les variable sur cette ligne.
    _ vérifie leur initialisation.
    _ vérifie que tu n'ecris pas dessus alors qu'elles ne sont pas allouer.

    ça c'est en solo, ensuite pour que je te file un coup de main:
    _ poste les invalid write et read qui concernent ton code.
    _ poste les fonctions qui contiennent les invalid read ou write, voir tout le code, que je puisse l'analyser, et le problème sera résolu rapidement .
    Pas de solution, pas de probleme

    Une réponse utile (ou +1) ->
    Une réponse inutile ou pas d'accord -> et expliquer pourquoi
    Une réponse à votre question


  7. #7
    Invité
    Invité(e)
    Par défaut
    Je n'ai pas de invalid read/write par contre j'ai un problème avec valgrind :

    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
     
    valgrind ./ODFAEG-DEMO
    ==24255== Memcheck, a memory error detector
    ==24255== Copyright (C) 2002-2013, and GNU GPL'd, by Julian Seward et al.
    ==24255== Using Valgrind-3.10.0.SVN and LibVEX; rerun with -h for copyright info
    ==24255== Command: ./ODFAEG-DEMO
    ==24255== 
    Direct GLX rendering context obtained
    Direct GLX rendering context obtained
    Created GL 3.0 context
    Direct GLX rendering context obtained
    Glew initialized!
    0x49e9d8
    vex amd64->IR: unhandled instruction bytes: 0xF0 0xED 0x49 0x0 0x0 0x0 0x0 0x0
    vex amd64->IR:   REX=0 REX.W=0 REX.R=0 REX.X=0 REX.B=0
    vex amd64->IR:   VEX=0 VEX.L=0 VEX.nVVVV=0x0 ESC=NONE
    vex amd64->IR:   PFX.66=0 PFX.F2=0 PFX.F3=0
    ==24255== valgrind: Unrecognised instruction at address 0xf87b360.
    ==24255==    at 0xF87B360: ???
    ==24255==    by 0x61BDEC4: (below main) (libc-start.c:287)
    ==24255== Your program just tried to execute an instruction that Valgrind
    ==24255== did not recognise.  There are two possible reasons for this.
    ==24255== 1. Your program has a bug and erroneously jumped to a non-code
    ==24255==    location.  If you are running Memcheck and you just saw a
    ==24255==    warning about a bad jump, it's probably your program's fault.
    ==24255== 2. The instruction is legitimate but Valgrind doesn't handle it,
    ==24255==    i.e. it's Valgrind's fault.  If you think this is the case or
    ==24255==    you are not sure, please let us know and we'll try to fix it.
    ==24255== Either way, Valgrind will now raise a SIGILL signal which will
    ==24255== probably kill your program.
    ==24255== 
    ==24255== Process terminating with default action of signal 4 (SIGILL)
    ==24255==  Illegal opcode at address 0xF87B360
    ==24255==    at 0xF87B360: ???
    ==24255==    by 0x61BDEC4: (below main) (libc-start.c:287)
    ==24255== 
    ==24255== HEAP SUMMARY:
    ==24255==     in use at exit: 4,254,002 bytes in 6,639 blocks
    ==24255==   total heap usage: 15,346 allocs, 8,707 frees, 8,722,836 bytes allocated
    ==24255== 
    ==24255== LEAK SUMMARY:
    ==24255==    definitely lost: 1,032 bytes in 1 blocks
    ==24255==    indirectly lost: 485 bytes in 8 blocks
    ==24255==      possibly lost: 93,008 bytes in 1,179 blocks
    ==24255==    still reachable: 4,159,477 bytes in 5,451 blocks
    ==24255==         suppressed: 0 bytes in 0 blocks
    ==24255== Rerun with --leak-check=full to see details of leaked memory
    ==24255== 
    ==24255== For counts of detected and suppressed errors, rerun with: -v
    ==24255== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 3 from 2)
    Processus arrêté
    Sinon j'ai des erreurs avec conditionnal jump or move depend on uninitialized value. (Je ne sais pas trop ce que ça signifier)

    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
     
    ==24050== Conditional jump or move depends on uninitialised value(s)
    ==24050==    at 0x471A90: odfaeg::g2d::PonctualLight::operator==(odfaeg::g2d::Entity&) (ponctualLight.cpp:377)
    ==24050==    by 0x495C89: odfaeg::g2d::GridMap::addEntity(odfaeg::g2d::Entity*) (cellMap.tpp:70)
    ==24050==    by 0x47E3F6: odfaeg::g2d::Map::addEntity(odfaeg::g2d::Entity*) (map.cpp:358)
    ==24050==    by 0x43D339: MyAppli::onInit() (entityManager.h:52)
    ==24050==    by 0x43005E: main (application.h:94)
    ==24050== 
    ==24050== Conditional jump or move depends on uninitialised value(s)
    ==24050==    at 0x471A90: odfaeg::g2d::PonctualLight::operator==(odfaeg::g2d::Entity&) (ponctualLight.cpp:377)
    ==24050==    by 0x495C89: odfaeg::g2d::GridMap::addEntity(odfaeg::g2d::Entity*) (cellMap.tpp:70)
    ==24050==    by 0x47E3F6: odfaeg::g2d::Map::addEntity(odfaeg::g2d::Entity*) (map.cpp:358)
    ==24050==    by 0x43D31A: MyAppli::onInit() (entityManager.h:52)
    ==24050==    by 0x43005E: main (application.h:94)
    ==24050== 
    Failed to load image "tilesets/vlad_sword.png". Reason : can't fopen
    terminate called after throwing an instance of 'odfaeg::Erreur'
      what():  ResourceManager::load - Failed to load 
    ==24050== 
    ==24050== HEAP SUMMARY:
    ==24050==     in use at exit: 16,463,661 bytes in 54,878 blocks
    ==24050==   total heap usage: 123,532 allocs, 68,654 frees, 52,483,301 bytes allocated
    ==24050== 
    ==24050== LEAK SUMMARY:
    ==24050==    definitely lost: 21,078 bytes in 468 blocks
    ==24050==    indirectly lost: 0 bytes in 0 blocks
    ==24050==      possibly lost: 4,277,188 bytes in 37,214 blocks
    ==24050==    still reachable: 12,165,395 bytes in 17,196 blocks
    ==24050==         suppressed: 0 bytes in 0 blocks
    ==24050== Rerun with --leak-check=full to see details of leaked memory
    ==24050== 
    ==24050== For counts of detected and suppressed errors, rerun with: -v
    ==24050== Use --track-origins=yes to see where uninitialised values come from
    ==24050== ERROR SUMMARY: 20 errors from 2 contexts (suppressed: 3 from 2)
    Processus arrêté
    Tu veux la fonction qui pose problème ???

    Je vois que je vais devoir regarder pour les "memory leak" également, il y a l'air d'en avoir pas mal également. (Ou bien alors j'utilise des shared et unique ptr.

    PS : Bien que la plupart des memory leaks que je vois proviennent des librairies linux (et principalement de la librairie x11 et de SFML) donc, ça n'est pas de moi. :/
    Dernière modification par Invité ; 20/08/2014 à 17h12.

  8. #8
    Membre émérite
    Avatar de skeud
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Juin 2011
    Messages
    1 091
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 34
    Localisation : France, Loire Atlantique (Pays de la Loire)

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Juin 2011
    Messages : 1 091
    Points : 2 724
    Points
    2 724
    Billets dans le blog
    1
    Par défaut
    ça pourrait venir de la, essaye de corriger toutes les erreurs appartenant à ton code, normalement ton problème sera résolu .
    Pas de solution, pas de probleme

    Une réponse utile (ou +1) ->
    Une réponse inutile ou pas d'accord -> et expliquer pourquoi
    Une réponse à votre question


  9. #9
    Invité
    Invité(e)
    Par défaut
    Salut, je ne parviens pas à trouver l'erreur, valgrind semble m'indiquer 2 erreurs :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
     
    ==32353== Conditional jump or move depends on uninitialised value(s)
    ==32353==    at 0x61EB7A7: __printf_fp (printf_fp.c:400)
    ==32353==    by 0x61EAA52: vfprintf (vfprintf.c:1660)
    ==32353==    by 0x620F3C8: vsnprintf (vsnprintf.c:119)
    ==32353==    by 0x59FFFAF: ??? (in /usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.19)
    ==32353==    by 0x5A06423: std::ostreambuf_iterator<char, std::char_traits<char> > std::num_put<char, std::ostreambuf_iterator<char, std::char_traits<char> > >::_M_insert_float<double>(std::ostreambuf_iterator<char, std::char_traits<char> >, std::ios_base&, char, char, double) const (in /usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.19)
    ==32353==    by 0x5A0670F: std::num_put<char, std::ostreambuf_iterator<char, std::char_traits<char> > >::do_put(std::ostreambuf_iterator<char, std::char_traits<char> >, std::ios_base&, char, double) const (in /usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.19)
    ==32353==    by 0x5A11CA4: std::ostream& std::ostream::_M_insert<double>(double) (in /usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.19)
    ==32353==    by 0x43324F: void odfaeg::OTextArchive::operator()<odfaeg::BoundingVolume, , void, void, void, void>(odfaeg::BoundingVolume*) (ostream:228)
    ==32353==    by 0x42F7CF: main (main.cpp:63)
    ==32353==  Uninitialised value was created by a heap allocation
    ==32353==    at 0x4C2B0E0: operator new(unsigned long) (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
    ==32353==    by 0x42F607: main (main.cpp:40)
    Ca veut dire quoi Unitialized value was created by heap allocation ?

    Il me dit que il y a un problème lors de la création de cette variable :

    Code cpp : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
     
    odfaeg::BoundingVolume* b1 = new odfaeg::BoundingSphere(odfaeg::Vec3f(0, 0, 0), 100);

    Y a t'il une erreur dans ce code ???

    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(BOUNDINGVOLUMEKEY, 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

    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
    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
     
    #include "../../../include/odfaeg/Physics/boundingSphere.h"
    #include "../../../include/odfaeg/Physics/boundingEllipsoid.h"
    #include "../../../include/odfaeg/Physics/boundingBox.h"
    #include "../../../include/odfaeg/Physics/orientedBoundingBox.h"
    #include "../../../include/odfaeg/Physics/boundingPolyhedron.h"
    #include "../../../include/odfaeg/Graphics/transformMatrix.h"
    using namespace std;
    namespace odfaeg {
    /*Crée un cercle englobant, utilisé pour les détection de collisions, et la sélection
    * d'objets.
    */
    //Crée un cercle de centre center et de rayon radius.
    BoundingSphere::BoundingSphere()  : Interface<BoundingSphere>(*this) {}
    BoundingSphere::BoundingSphere (Vec3f center, float radius) : Interface<BoundingSphere>(*this) {
        this->center = center;
        this->radius = radius;
    }
    bool BoundingSphere::onIntersects (BoundingVolume& interface) {
         return intersects(static_cast<BoundingSphere&>(interface));
    }
    bool BoundingSphere::intersects (BoundingSphere &other) {
        float d = center.computeDist (other.center);
        float rSum = radius + other.radius;
        return (d <= rSum);
    }
    bool BoundingSphere::intersects (BoundingEllipsoid &be) {
        return be.intersects(*this);
    }
    bool BoundingSphere::intersects (BoundingBox &bx) {
        Vec3f d = bx.getCenter() - center;
        float m = center.computeDist(bx.getCenter());
        Vec3f near, far;
        Ray r (bx.getCenter(), center);
        intersectsWhere(r, near, far);
        Vec3f d2 = near - center;
        int ray2 = d2.projOnAxis(d);
        float hi[3];
        hi[0] = bx.getWidth() * 0.5f;
        hi[1] = bx.getHeight() * 0.5f;
        hi[2] = bx.getHeight() * 0.5f;
        for (int i = 0; i < 3; i++) {
            int rSum = radius + hi[i];
            if (m - rSum > 0.f)
                return false;
        }
        return true;
    }
     
    bool BoundingSphere::intersects (OrientedBoundingBox &obx) {
        Vec3f d = obx.getCenter() - center;
        float m = center.computeDist(obx.getCenter());
        Vec3f near, far;
        Ray r(obx.getCenter(), center);
        intersectsWhere(r, near, far);
        Vec3f d2 = near - center;
        int ray2 = d2.projOnAxis(d);
        Vec3f bi[3];
        bi[0] = obx.getBX() * obx.getWidth() * 0.5f;
        bi[1] = obx.getBY() * obx.getHeight() * 0.5f;
        bi[2] = obx.getBZ() * obx.getDepth() * 0.5f;
        for (int i = 0; i < 3; i++) {
            float ray2 = bi[i].projOnAxis(d);
            int rSum = radius + ray2;
            if (m - rSum > 0.f)
                return true;
        }
        return false;
    }
    bool BoundingSphere::intersects (BoundingPolyhedron &bp) {
        Vec3f d = bp.getCenter() - center;
        float m = center.computeDist(bp.getCenter());
        Vec3f near, far;
        Ray r(bp.getCenter(), center);
        intersectsWhere(r, near, far);
        Vec3f d2 = near - center;
        int ray2 = d2.projOnAxis(d);
        Vec3f a = bp.getPoint(0);
        Vec3f b = bp.getPoint(1);
        Vec3f mid = a + (b - a) * 0.5f;
        Vec3f bi = mid - bp.getCenter();
        float proj = bi.projOnAxis(d);
        int min = proj;
        int max = proj;
        for (unsigned int j = 1; j < bp.nbPoints(); j++) {
           a = bp.getPoint(j);
           if (j != bp.nbPoints() - 1)
               b = bp.getPoint(j+1);
           else
               b = bp.getPoint(0);
           mid = a + (b - a) * 0.5f;
           bi = (mid - bp.getCenter()) * 0.5f;
           proj = bi.projOnAxis(d);
           if (proj < min)
               min = proj;
           if (proj > max)
               max = proj;
        }
        ray2 = max - min;
        int rSum = radius + ray2;
        if (m - rSum > 0.f)
            return true;
        return false;
    }
    bool BoundingSphere::intersects (Ray &ray) {
        float c = radius;
        Vec3f d1 = ray.getExt() - center;
        Vec3f d2 = ray.getOrig() - center;
        Vec3f b = (ray.getOrig() + ray.getExt()) * 0.5f - center;
        Vec3f norm (ray.getOrig().y - ray.getExt().y, ray.getExt().x - ray.getOrig().x, ray.getExt().z - ray.getOrig().z);
        if (b.dot2(norm) < 0)
            norm = -norm;
        Vec3f n = b.projOnVector(norm);
        float r1 = d1.projOnAxis(n);
        float r2 = d2.projOnAxis(n);
        if (r1 - c > 0 && r2 - c > 0)
            return false;
        return true;
     
    }
    bool BoundingSphere::intersectsWhere (Ray& r, Vec3f& near, Vec3f &far) {
        Vec3f d = r.getOrig() - center;
        float a = r.getDir().dot(r.getDir());
        float b = 2 * r.getDir().dot(d);
        float c = d.dot(d) - (radius * radius);
        float disc = b * b - 4 *  a * c;
        if (disc < 0)
            return false;
        float distSqrt = Math::sqrt(disc);
        float q;
        if (b < 0)
            q = (-b - distSqrt)/2.0;
        else
            q = (-b + distSqrt)/2.0;
     
        // compute t0 and t1
        float t0 = q / a;
        float t1 = c / q;
     
        // make sure t0 is smaller than t1
        if (t0 > t1)
        {
            // if t0 is bigger than t1 swap them around
            float temp = t0;
            t0 = t1;
            t1 = temp;
        }
     
        // if t1 is less than zero, the object is in the ray's negative direction
        // and consequently the ray misses the sphere
        if (t1 < 0)
            return false;
     
        // if t0 is less than zero, the intersection point is at t1
        bool intersects = false;
        if (t0 < 0)
        {
            near = r.getOrig() + r.getDir() * t1;
            intersects = true;
        }
        // else the intersection point is at t0
        else
        {
            far = r.getOrig() + r.getDir() * t0;
            if (!intersects)
                intersects = true;
        }
        return intersects;
    }
    //Test si un point est à l'intérieur du cercle.
    bool BoundingSphere::isPointInside (Vec3f &point) {
        float d = center.computeDist(point);
        return d < radius;
    }
    Vec3f BoundingSphere::getPosition() {
        return Vec3f(center.x - radius, center.y - radius, center.z - radius);
    }
    Vec3f BoundingSphere::getCenter() {
        return center;
    }
    Vec3f BoundingSphere::getSize() {
        return Vec3f(radius * 2, radius * 2, radius * 2);
    }
    float BoundingSphere::getRadius () {
        return radius;
    }
    }

    La deuxième erreur concerne le flux, lorsque j'essaye d'écrire l'objet dans l'archive, il me dit que il y a une variable utilisée dans une condition qui n'est pas initialisée, y a t'il une erreur dans ce code ?

    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
     
     template <class O,
                  class... D,
                  class = typename std::enable_if<!std::is_fundamental<O>::value>::type,
                  class = typename std::enable_if<!std::is_same<O, std::string>::value>::type,
                  class = typename std::enable_if<has_typedef_key<O>::value>::type,
                  class = typename std::enable_if<!sizeof...(D)>::type>
        void operator() (O* object, D...) {
            std::map<unsigned long long int, unsigned long long int>::iterator it = adresses.find(reinterpret_cast<unsigned long long int>(object));
            if (it != adresses.end()) {
                buffer<<it->second<<" ";
            } else {
                int index = -1;
                std::pair<unsigned long long int, unsigned long long int> newAddress (reinterpret_cast<unsigned long long int>(object), nbSerialized);
                adresses.insert(newAddress);
                if (typeid(decltype(*object)) == typeid(*object)) {
                    std::cout<<"non polymoprhic version"<<std::endl;
                    buffer<<newAddress.second<<" ";
                    buffer<<index<<" ";
                    object->serialize(*this);
                } else {
                    std::cout<<"polymoprhic version"<<std::endl;
                    object->key.register_object(object);
                    index = object->key.getTypeIndex();
                    buffer<<newAddress.second<<" ";
                    buffer<<index<<" ";
                    object->key.serialize_object(*this, 0);
                }
                nbSerialized++;
            }
        }

    Sachant que j'utilise SFINAE donc il y a des templates qui ont la valeur void, je ne sais pas si c'est ça qui fais que valgrind me ressors une erreur mais pour la 1ère je ne vois vraiment pas ce que c'est...

    PS : je n'ai pas vraiment les bonne valeur pour le centre de la sphere lorsque je les écris dans le fichier donc je pense que le problème vient bien de l'allocation de la sphère mais je ne vois pas trop ou est l'erreur.
    Dernière modification par Invité ; 20/08/2014 à 22h05.

  10. #10
    Invité
    Invité(e)
    Par défaut
    Ha, y'a du nouveau!

    J'ai réglé ces quelques soucis d'initilization en rajoutant une méthode initialize pour initializer tout les éléments du tuple à nullptr :

    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
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
     
    #ifndef ODFAEG_SERIALIZATION
    #define ODFAEG_SERIALIZATION
    #include <iostream>
    #include <typeinfo>
    #include "tuple.h"
    #include <tuple>
    namespace odfaeg {
    template <int N, typename B, typename T, typename A>
    struct serializer {
        static void checkType (B* base, T tuple, A & ar) {
            if (std::get<N>(tuple) != nullptr && typeid(*base) == typeid(*std::get<N>(tuple))) {
                std::get<N>(tuple)->serialize(ar);
            }
            serializer<N-1, B, T, A>::checkType(base, tuple, ar);
        }
    };
    template <typename B, typename T, typename A>
    struct serializer <0, B, T, A> {
        static void checkType (B* base, T tuple, A & ar) {
            if (std::get<0>(tuple) != nullptr && typeid(*base) == typeid(*std::get<0>(tuple))) {
                std::get<0>(tuple)->serialize(ar);
            } else if (base != nullptr) {
                base->serialize(ar);
            }
     
        }
    };
    template <int N, typename T>
    struct sinitializer {
        static void initialize (T tuple) {
           std::get<N>(tuple) = nullptr;
           sinitializer<N-1, T>::initialize(tuple);
        }
    };
    template <typename T>
    struct sinitializer <0, T> {
        static void initialize (T tuple) {
           std::get<0>(tuple) = nullptr;
        }
    };
    template <int N, typename B, typename T>
    struct sallocator {
        static B* instanciate (int index, T tuple) {
            if (N == index) {
                using D = typename std::remove_pointer<typename std::tuple_element<N, T>::type>::type;
                return new D();
            }
            sallocator<N-1, B, T>::instanciate(index, tuple);
        }
    };
    template <typename B, typename T>
    struct sallocator <0, B, T> {
        static B* instanciate (int index, T tuple) {
            using D = typename std::remove_pointer<typename std::tuple_element<0, T>::type>::type;
            return new D();
        }
    };
    template <int N, typename B, typename T>
    struct sindex {
        static int getIndex (B* base, T tuple) {
            if (std::get<N>(tuple) != nullptr && typeid(*base) == typeid(*std::get<N>(tuple))) {
                return N;
            }
            sindex<N-1, B, T>::getIndex(base, tuple);
        }
    };
    template <typename B, typename T>
    struct sindex <0, B, T> {
        static int getIndex (B* base, T tuple) {
            using D = typename std::remove_pointer<typename std::tuple_element<0, T>::type>::type;
            D* derived = new D();
            if (std::get<0>(tuple) != nullptr && typeid(*base) == typeid(*std::get<0>(tuple))) {
                return 0;
            }
            return -1;
        }
    };
     
    template <class B, class... D>
    class Serializer {
        public :
        Serializer() {
            baseObject = nullptr;
            if (std::tuple_size<decltype(derivedClasses)>::value > 0)
                sinitializer<std::tuple_size<decltype(derivedClasses)>::value-1, decltype(derivedClasses)>::initialize(derivedClasses);
        }
        Serializer(B* baseObject) : baseObject(baseObject) {
            fillTuple(derivedClasses);
        }
        void setObject(B* baseObject) {
            this->baseObject = baseObject;
            fillTuple(derivedClasses);
        }
        template<int... S>
        void fillTuple(std::tuple<D*...> types) {
            fillTuple(typename helper::gens<sizeof...(D)>::type(), types);
        }
        template<int... S>
        void fillTuple(helper::seq<S...>, std::tuple<D*...> params) {
             derivedClasses = std::forward_as_tuple(dynamic_cast<typename std::remove_reference<decltype(std::get<S>(params))>::type> (baseObject)...);
        }
        template <typename Archive>
        void serialize(Archive & ar) {
            if (std::tuple_size<decltype(derivedClasses)>::value > 0)
                serializer<std::tuple_size<decltype(derivedClasses)>::value-1, B, decltype(derivedClasses), Archive>::checkType(baseObject, derivedClasses, ar);
            else
                baseObject->serialize(ar);
        }
        virtual void onSave() {
        }
        virtual void onLoad() {
        }
        B* sallocate(int index) {
            if (std::tuple_size<decltype(derivedClasses)>::value > 0)
                return sallocator<std::tuple_size<decltype(derivedClasses)>::value-1, B, decltype(derivedClasses)>::instanciate(index, derivedClasses);
     
        }
        int getIndex() {
            if (std::tuple_size<decltype(derivedClasses)>::value > 0)
                return sindex<std::tuple_size<decltype(derivedClasses)>::value-1, B, decltype(derivedClasses)>::getIndex(baseObject, derivedClasses);
            return -1;
        }
        private :
        B* baseObject;
        std::tuple<D*...> derivedClasses;
    };
    }
    #endif // SERIALIZATION

    Pareil dans la macro j'ai rajouté ceci pour être sûr que tout soit bien initializé :

    Code cpp : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
     
    #include "serialization.h"
    #define REGISTER_KEY(KEY, TYPE, TYPES...)  \
    struct KEY : public  odfaeg::Serializer<TYPE, TYPES> { \
        public : \
        KEY () : odfaeg::Serializer<TYPE, TYPES>() {}

    Tout est bien initialisé et là je me retrouve bien avec un pointeur qui reste null.

    Code cpp : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
     
     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<<tile->getCollisionVolume()<<std::endl;

    Hors que ce n'étais pas le cas avant.

    Cependant, j'ai toujours ce foutu crash à l'exécution!

  11. #11
    Membre émérite
    Avatar de skeud
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Juin 2011
    Messages
    1 091
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 34
    Localisation : France, Loire Atlantique (Pays de la Loire)

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Juin 2011
    Messages : 1 091
    Points : 2 724
    Points
    2 724
    Billets dans le blog
    1
    Par défaut
    Essaye de trouvé où le code plante exactement avec valgrind, normalement, tu devrais pouvoir el corriger facilement de cette manière.

    N'hésite pas à rajouter du debug (à coup de std::cout pour savoir exactement la valeur de tes variable).

    En gros, avec valgrind tu vois où le code plante, puis avec des std::cout tu affiche les adresse de tes variables. L'erreur que tu obtiens lors du crash indique que tu utilise une variable non allouée.
    Pas de solution, pas de probleme

    Une réponse utile (ou +1) ->
    Une réponse inutile ou pas d'accord -> et expliquer pourquoi
    Une réponse à votre question


  12. #12
    Invité
    Invité(e)
    Par défaut
    Ha oui j'ai oublié de précisé, j'ai un invalid read par contre il ne me met pas de numéro de ligne dans mon code, mais juste une ligne dans libc-start.c. (la ligne 287)

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
     
    ==7719== Invalid read of size 1
    ==7719==    at 0xF7E64DF: ???
    ==7719==    by 0x61BDEC4: (below main) (libc-start.c:287)
    ==7719==  Address 0xf8de038 is not stack'd, malloc'd or (recently) free'd
    ==7719== 
    ==7719== Jump to the invalid address stated on the next line
    ==7719==    at 0xF7E65CA: ???
    ==7719==    by 0x61BDEC4: (below main) (libc-start.c:287)
    ==7719==  Address 0xf7e65ca is not stack'd, malloc'd or (recently) free'd
    ==7719==
    Pourtant, j'ai bien compilé avec l'option -g. (En mode debug)

    c'est quoi ce fichier libc-start.c, c'est un fichier de la librairie du c, ou bien c'est un fichier de valgrind ? (Je pense que ça doit provenir de la stl)

  13. #13
    Membre émérite
    Avatar de skeud
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Juin 2011
    Messages
    1 091
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 34
    Localisation : France, Loire Atlantique (Pays de la Loire)

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Juin 2011
    Messages : 1 091
    Points : 2 724
    Points
    2 724
    Billets dans le blog
    1
    Par défaut
    normalement, tu ne devrais pas t'en soucié, essaye de recompiler tout ton code (pour tout regénéré) et poste la sortie complète de valgrind stp .
    Pas de solution, pas de probleme

    Une réponse utile (ou +1) ->
    Une réponse inutile ou pas d'accord -> et expliquer pourquoi
    Une réponse à votre question


  14. #14
    Invité
    Invité(e)
    Par défaut
    Ok, j'ai tout recompilé, voici la sortie complète de valgrind :

    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
     
    ==8895== Invalid read of size 1
    ==8895==    at 0xF7E87A0: ???
    ==8895==    by 0x61BDEC4: (below main) (libc-start.c:287)
    ==8895==  Address 0xf7e910e is 14 bytes inside a block of size 36 free'd
    ==8895==    at 0x4C2BDEC: free (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
    ==8895==    by 0x6ACCFC4: _XEventsQueued (in /usr/lib/x86_64-linux-gnu/libX11.so.6.3.0)
    ==8895==    by 0x6AAA6BC: XCheckIfEvent (in /usr/lib/x86_64-linux-gnu/libX11.so.6.3.0)
    ==8895==    by 0x50866AC: sf::priv::WindowImplX11::processEvents() (in /usr/local/lib/libsfml-window.so.2.1)
    ==8895==    by 0x50821AD: sf::priv::WindowImpl::popEvent(sf::Event&, bool) (in /usr/local/lib/libsfml-window.so.2.1)
    ==8895==    by 0x50809AB: sf::Window::pollEvent(sf::Event&) (in /usr/local/lib/libsfml-window.so.2.1)
    ==8895==    by 0x43368D: main (main.cpp:46)
    ==8895== 
    ==8895== Invalid read of size 1
    ==8895==    at 0xF7E87A7: ???
    ==8895==    by 0x61BDEC4: (below main) (libc-start.c:287)
    ==8895==  Address 0xf8e02bb is not stack'd, malloc'd or (recently) free'd
    ==8895== 
    ==8895== Invalid read of size 1
    ==8895==    at 0xF7E87AF: ???
    ==8895==    by 0x61BDEC4: (below main) (libc-start.c:287)
    ==8895==  Address 0xf8e02bb is not stack'd, malloc'd or (recently) free'd
    ==8895== 
    vex amd64->IR: unhandled instruction bytes: 0xF 0x0 0x0 0x0 0x0 0x5 0x0 0x0
    vex amd64->IR:   REX=0 REX.W=0 REX.R=0 REX.X=0 REX.B=0
    vex amd64->IR:   VEX=0 VEX.L=0 VEX.nVVVV=0x0 ESC=0F
    vex amd64->IR:   PFX.66=0 PFX.F2=0 PFX.F3=0
    ==8895== valgrind: Unrecognised instruction at address 0xf7e87cb.
    ==8895==    at 0xF7E87CB: ???
    ==8895==    by 0x61BDEC4: (below main) (libc-start.c:287)
    ==8895== Your program just tried to execute an instruction that Valgrind
    ==8895== did not recognise.  There are two possible reasons for this.
    ==8895== 1. Your program has a bug and erroneously jumped to a non-code
    ==8895==    location.  If you are running Memcheck and you just saw a
    ==8895==    warning about a bad jump, it's probably your program's fault.
    ==8895== 2. The instruction is legitimate but Valgrind doesn't handle it,
    ==8895==    i.e. it's Valgrind's fault.  If you think this is the case or
    ==8895==    you are not sure, please let us know and we'll try to fix it.
    ==8895== Either way, Valgrind will now raise a SIGILL signal which will
    ==8895== probably kill your program.
    ==8895== 
    ==8895== Process terminating with default action of signal 4 (SIGILL)
    ==8895==  Illegal opcode at address 0xF7E87CB
    ==8895==    at 0xF7E87CB: ???
    ==8895==    by 0x61BDEC4: (below main) (libc-start.c:287)
    ==8895== 
    ==8895== HEAP SUMMARY:
    ==8895==     in use at exit: 3,970,063 bytes in 6,674 blocks
    ==8895==   total heap usage: 15,499 allocs, 8,825 frees, 8,125,623 bytes allocated
    ==8895== 
    ==8895== LEAK SUMMARY:
    ==8895==    definitely lost: 8 bytes in 1 blocks
    ==8895==    indirectly lost: 440 bytes in 6 blocks
    ==8895==      possibly lost: 93,002 bytes in 1,179 blocks
    ==8895==    still reachable: 3,876,613 bytes in 5,488 blocks
    ==8895==         suppressed: 0 bytes in 0 blocks
    ==8895== Rerun with --leak-check=full to see details of leaked memory
    ==8895== 
    ==8895== For counts of detected and suppressed errors, rerun with: -v
    ==8895== ERROR SUMMARY: 6 errors from 3 contexts (suppressed: 3 from 2)
    Processus arrêté
    L'invalid read survient lorsque j'essaye de lire le pointeur ici :

    Code cpp : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
     
    std::cout<<tile->getCollisionVolume()<<std::endl;

    Que pourtant, j'initialise bien ici :
    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
     
    Entity::Entity (Vec3f position, Vec3f size, Vec3f origin, std::string sType, Entity *parent) :
        Transformable (position, size, origin), Drawable(), entityState("Entity State", nullptr) {
        this->parent = parent;
        types = initTypes();
        int iType = getIntOfType(sType);
        if (iType == -1) {
            type = std::pair<int, std::string> (nbEntitiesTypes, sType);
            types->insert(type);
            nbEntitiesTypes++;
        } else {
            std::map<int, std::string>::iterator it = types->find(iType);
            type = *it;
        }
        id = nbEntities;
        nbEntities++;
        collisionVolume = nullptr;
    }

    Mais le crash ne survient uniquement lorsque j'essaye d'afficher la tile, donc,c'est peut être un problème dans le module window de SFML (ou bien dans libX11)

    Ou bien (et je pense que c'est plutôt là), dans libc-start.c.

  15. #15
    Membre émérite
    Avatar de skeud
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Juin 2011
    Messages
    1 091
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 34
    Localisation : France, Loire Atlantique (Pays de la Loire)

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Juin 2011
    Messages : 1 091
    Points : 2 724
    Points
    2 724
    Billets dans le blog
    1
    Par défaut
    poste le code de ton main stp .
    Pas de solution, pas de probleme

    Une réponse utile (ou +1) ->
    Une réponse inutile ou pas d'accord -> et expliquer pourquoi
    Une réponse à votre question


  16. #16
    Invité
    Invité(e)
    Par défaut
    Voici le code du 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
     
    #define BVKEY REGISTER_KEY(BOUNDINGVOLUMKEY, odfaeg::BoundingVolume, odfaeg::BoundingBox, odfaeg::BoundingSphere)
    #include "odfaeg/Core/archive.h"
    #include "odfaeg/Graphics/renderWindow.h"
    #include "odfaeg/Graphics/2D/tile.h"
    int main(int argc, char* args[])
    {
        sf::VideoMode mode(800, 600);
        sf::ContextSettings settings(0, 0, 4, 3, 0);
        odfaeg::RenderWindow window(mode, "test", sf::Style::Default, settings);
        odfaeg::Texture tex;
        tex.loadFromFile("tilesets/herbe.png");  
        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<<tile->getCollisionVolume()<<std::endl;
        while (window.isOpen()) {
            sf::Event event;
            while(window.pollEvent(event)) {
                if (event.type == sf::Event::Closed) {
                   window.close();
                }
            }
            window.clear();
            window.draw(*tile);
            window.display();
     
        } 
        delete tile;
        return 0;  
    }

    Bref, je ne vois rien de fâcheux dans le main pourtant. :/

  17. #17
    Membre émérite
    Avatar de skeud
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Juin 2011
    Messages
    1 091
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 34
    Localisation : France, Loire Atlantique (Pays de la Loire)

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Juin 2011
    Messages : 1 091
    Points : 2 724
    Points
    2 724
    Billets dans le blog
    1
    Par défaut
    Il semblerait que tu n'as pas mis tout le main, dans le valgrind il indique ligne 46, hors ton main ne va pas jusque la :p
    Pas de solution, pas de probleme

    Une réponse utile (ou +1) ->
    Une réponse inutile ou pas d'accord -> et expliquer pourquoi
    Une réponse à votre question


  18. #18
    Invité
    Invité(e)
    Par défaut
    Oui c'est parce que il y a du code que j'ai mis en commentaire dans le main et je n'ai pas voulu mettre du code inutile, la ligne 16 correspond en faire à ceci :

    Code cpp : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
     
    while(window.pollEvent(event)) {

  19. #19
    Invité
    Invité(e)
    Par défaut
    Voilà j'ai purgé le main mais j'ai une autre sortie avec valgrind. (J'ai trouvé d'où venait le invalid read en fait j'avais oublié de retiré un include mais j'ai toujours un crash dans libc-start.c)

    Voici 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
     
    #define BVKEY REGISTER_KEY(BOUNDINGVOLUMKEY, odfaeg::BoundingVolume, odfaeg::BoundingBox, odfaeg::BoundingSphere)
    #include "odfaeg/Graphics/renderWindow.h"
    #include "odfaeg/Graphics/2D/tile.h"
    int main(int argc, char* args[])
    {
        sf::VideoMode mode(800, 600);
        sf::ContextSettings settings(0, 0, 4, 3, 0);
        odfaeg::RenderWindow window(mode, "test", sf::Style::Default, settings);
        odfaeg::Texture tex;
        tex.loadFromFile("tilesets/herbe.png");
        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<<tile->getCollisionVolume()<<std::endl;
        while (window.isOpen()) {
            sf::Event event;
            while(window.pollEvent(event)) {
                if (event.type == sf::Event::Closed) {
                   window.close();
                }
            }
            window.clear();
            window.draw(*tile);
            window.display();
     
        }
        delete tile;
        return 0;
    }

    Et voici la sortie de valgrind :

    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
     
    # valgrind ./ODFAEG-DEMO
    ==10034== Memcheck, a memory error detector
    ==10034== Copyright (C) 2002-2013, and GNU GPL'd, by Julian Seward et al.
    ==10034== Using Valgrind-3.10.0.SVN and LibVEX; rerun with -h for copyright info
    ==10034== Command: ./ODFAEG-DEMO
    ==10034== 
    Direct GLX rendering context obtained
    Direct GLX rendering context obtained
    Created GL 3.0 context
    Direct GLX rendering context obtained
    Glew initialized!
    0
    vex amd64->IR: unhandled instruction bytes: 0x6E 0x7E 0xF 0x0 0x0 0x0 0x0 0x30
    vex amd64->IR:   REX=0 REX.W=0 REX.R=0 REX.X=0 REX.B=0
    vex amd64->IR:   VEX=0 VEX.L=0 VEX.nVVVV=0x0 ESC=NONE
    vex amd64->IR:   PFX.66=0 PFX.F2=0 PFX.F3=0
    ==10034== valgrind: Unrecognised instruction at address 0xf7e6a31.
    ==10034==    at 0xF7E6A31: ???
    ==10034==    by 0x61BDEC4: (below main) (libc-start.c:287)
    ==10034== Your program just tried to execute an instruction that Valgrind
    ==10034== did not recognise.  There are two possible reasons for this.
    ==10034== 1. Your program has a bug and erroneously jumped to a non-code
    ==10034==    location.  If you are running Memcheck and you just saw a
    ==10034==    warning about a bad jump, it's probably your program's fault.
    ==10034== 2. The instruction is legitimate but Valgrind doesn't handle it,
    ==10034==    i.e. it's Valgrind's fault.  If you think this is the case or
    ==10034==    you are not sure, please let us know and we'll try to fix it.
    ==10034== Either way, Valgrind will now raise a SIGILL signal which will
    ==10034== probably kill your program.
    ==10034== 
    ==10034== Process terminating with default action of signal 4 (SIGILL)
    ==10034==  Illegal opcode at address 0xF7E6A31
    ==10034==    at 0xF7E6A31: ???
    ==10034==    by 0x61BDEC4: (below main) (libc-start.c:287)
    ==10034== 
    ==10034== HEAP SUMMARY:
    ==10034==     in use at exit: 3,966,943 bytes in 6,659 blocks
    ==10034==   total heap usage: 15,421 allocs, 8,762 frees, 8,120,379 bytes allocated
    ==10034== 
    ==10034== LEAK SUMMARY:
    ==10034==    definitely lost: 8 bytes in 1 blocks
    ==10034==    indirectly lost: 440 bytes in 6 blocks
    ==10034==      possibly lost: 93,002 bytes in 1,179 blocks
    ==10034==    still reachable: 3,873,493 bytes in 5,473 blocks
    ==10034==         suppressed: 0 bytes in 0 blocks
    ==10034== Rerun with --leak-check=full to see details of leaked memory
    ==10034== 
    ==10034== For counts of detected and suppressed errors, rerun with: -v
    ==10034== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 3 from 2)
    Processus arrêté
    Je pense que je vais devoir me soucier de ce fichier libc-start qui semble faire tout foiré. :/

  20. #20
    Membre émérite
    Avatar de skeud
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Juin 2011
    Messages
    1 091
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 34
    Localisation : France, Loire Atlantique (Pays de la Loire)

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Juin 2011
    Messages : 1 091
    Points : 2 724
    Points
    2 724
    Billets dans le blog
    1
    Par défaut
    Je pense que c'est un soucis du à ta macro, mais pourquoi, je sais pas trop :/
    Met du debug dans le main pour savoir exactement où ça crash, genre à chaque ligne tu rajoute:
    std::cout << __line__ << std::endl;

    Comme ça on saura où ça foire.
    Pas de solution, pas de probleme

    Une réponse utile (ou +1) ->
    Une réponse inutile ou pas d'accord -> et expliquer pourquoi
    Une réponse à votre question


+ Répondre à la discussion
Cette discussion est résolue.
Page 1 sur 2 12 DernièreDernière

Discussions similaires

  1. Inclusion d'une partie du code source dans une documentation Doxygen
    Par feanor11 dans le forum Autres éditeurs
    Réponses: 2
    Dernier message: 01/02/2012, 17h29
  2. Réponses: 3
    Dernier message: 23/05/2011, 23h00
  3. Inclusion de Code Adsense dans un fichier
    Par badrel dans le forum Langage
    Réponses: 6
    Dernier message: 12/02/2009, 11h31
  4. Réponses: 15
    Dernier message: 16/01/2009, 00h16
  5. Réponses: 4
    Dernier message: 10/02/2005, 16h10

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo