xR3b0rn / dbcppp

C/C++ DBC file parser/tool
MIT License
232 stars 76 forks source link

Segmentation fault raised in Example #127

Closed Niuzu closed 2 years ago

Niuzu commented 2 years ago

The example Code given in the repository is generating a 'Segmentation fault'

dbcppp/examples/BasicUsage/main.cpp

Terminal:

Building CodeExample...
Scanning dependencies of target CodeExample
[ 50%] Building CXX object CMakeFiles/CodeExample.dir/main.cpp.o
[100%] Linking CXX executable CodeExample
[100%] Built target CodeExample
Segmentation fault

main.cpp:

int main()
{
    std::unique_ptr<dbcppp::INetwork> net;
    {
        std::ifstream idbc("TestingDbc.dbc");
        net = dbcppp::INetwork::LoadDBCFromIs(idbc);
    }
    std::unordered_map<uint64_t, const dbcppp::IMessage*> messages;
    for (const dbcppp::IMessage& msg : net->Messages()) /* Code generates Segmentation fault */
    {
        // messages.insert(std::make_pair(msg.Id(), &msg));
    }
}
xR3b0rn commented 2 years ago

You get an error, because net is nullptr. To make the example work, you have to provide your own TestingDbc.dbc.

Niuzu commented 2 years ago

Correct, my dbc was in a different folder than my binary. Thanks.