Hey guys,

An char* to string conversion looks to be generating a segfault. I'm pretty sure that's not it, but that's when GDB says it received one...

Well, here's the, what I think, relevant code. If you think more code is relevant I'll post that too of course.

Entity.h (objLocation definition, ctor definition)

public:
    entity(char *location, bool loadNow);
(...)
private:
(...)
    string objLocation;
};

Entity.cpp (constructor only)

entity::entity(char *modellocation, bool loadNow):
visible(true)
{
    for(int i = 0; i < 3; i++){
        location[i] = rotation[i] = 0;
    }

    objLocation = modellocation; //BOOM segfault. :(
    if(loadNow){
        loadentity();
    }

    return;
}

World.cpp (createAndAddEntity method, origin of the call to the entity constructor)

void world::createAndAddEntity(char *location, bool loadNow){
    entity *holdThis = new entity(location, loadNow);
    world::addEntity(holdThis);

    return;
}

And too make it just the bit more confusing for me:

main.cpp

scene.createAndAddEntity("C:\\Code\\BowViceJetDeux\\testobj\\anubis.obj", true);
    scene.createAndAddEntity("C:\\Code\\BowViceJetDeux\\testobj\\anubis.obj", true);

First works good, second one gives that segfault mentioned earlier. Why does it do that? :(

Thanks in Advance,
Nick

Oh, the backtrace that is offered, is not really useful. It looks like it's data:

#0 7D62BD7E	??() (??:??)
#1 00000036	??() (??:??)
#2 003F0000	??() (??:??)
#3 00000001	??() (??:??)
#4 7D623710	??() (??:??)
#5 003F0000	??() (??:??)
#6 7D61CA05	??() (??:??)
#7 7D623938	??() (??:??)
#8 FFFFFFFF	??() (??:??)
#9 0022F58C	??() (??:??)
#10 0000159A	??() (??:??)
#11 0022F57C	??() (??:??)
#12 7D623710	??() (??:??)
#13 003F0000	??() (??:??)
#14 03882330	??() (??:??)
#15 003F0000	??() (??:??)
#16 03882330	??() (??:??)
#17 00001103	??() (??:??)
#18 03840000	??() (??:??)
#19 0100039A	??() (??:??)
#20 0022F5B0	??() (??:??)
#21 7D623A9A	??() (??:??)
#22 0000159A	??() (??:??)
#23 10882330	??() (??:??)
#24 00000000	??() (??:??)

When I run the code, but remove that second line, it also segfaults! But, when changing the object, the file I'm passing, it doesn't segfault... However, I don't understand that it always segfaults with the same object (and doesn't with others). Anyone with a fair share of OpenGL knowledge? Maybe I'm messing up somewhere. I use GLUT by the way, on my windows machine. So it's ported, obviously.

Hey, this code executes flawlessly:

scene.createAndAddEntity("C:\\Code\\BowViceJetDeux\\testobj\\digi.obj", true);
    scene.createAndAddEntity("C:\\Code\\BowViceJetDeux\\testobj\\digi.obj", true);
    scene.createAndAddEntity("C:\\Code\\BowViceJetDeux\\testobj\\digi.obj", true);
    scene.createAndAddEntity("C:\\Code\\BowViceJetDeux\\testobj\\digi.obj", true);
    scene.createAndAddEntity("C:\\Code\\BowViceJetDeux\\testobj\\digi.obj", true);
    scene.createAndAddEntity("C:\\Code\\BowViceJetDeux\\testobj\\digi.obj", true);
    scene.createAndAddEntity("C:\\Code\\BowViceJetDeux\\testobj\\digi.obj", true);
    scene.createAndAddEntity("C:\\Code\\BowViceJetDeux\\testobj\\digi.obj", true);
    scene.createAndAddEntity("C:\\Code\\BowViceJetDeux\\testobj\\digi.obj", true);
    scene.createAndAddEntity("C:\\Code\\BowViceJetDeux\\testobj\\digi.obj", true);
    scene.createAndAddEntity("C:\\Code\\BowViceJetDeux\\testobj\\digi.obj", true);
    scene.createAndAddEntity("C:\\Code\\BowViceJetDeux\\testobj\\digi.obj", true);
    scene.createAndAddEntity("C:\\Code\\BowViceJetDeux\\testobj\\digi.obj", true);
    scene.createAndAddEntity("C:\\Code\\BowViceJetDeux\\testobj\\digi.obj", true);
    scene.createAndAddEntity("C:\\Code\\BowViceJetDeux\\testobj\\digi.obj", true);
    scene.createAndAddEntity("C:\\Code\\BowViceJetDeux\\testobj\\digi.obj", true);
    scene.createAndAddEntity("C:\\Code\\BowViceJetDeux\\testobj\\digi.obj", true);

I also added a extra line in the .obj parser, and pretty sure the error is in their when checking it's additional output (when loading anubis.obj)

Counting...WARNING: Line not supported:
WARNING: Line not supported:
WARNING: Line not supported:
WARNING: Line not supported:
WARNING: Line not supported: g Anubis head
WARNING: Line not supported:
WARNING: Line not supported: g Anubis garment
WARNING: Line not supported: //3525 2906//3436
WARNING: Line not supported: 41 2860//3237 2863//3240

See, those last two warnings are reallllyyy important! Hahaha, I'm rechecking that part, pretty sure that if I fix that error, the char* to string conversion will work like a charm. ;)

This article has been dead for over six months. Start a new discussion instead.