Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Segmentation fault on saving json to file #326

Closed
aeon0 opened this issue Oct 11, 2016 · 7 comments
Closed

Segmentation fault on saving json to file #326

aeon0 opened this issue Oct 11, 2016 · 7 comments
Labels
solution: invalid the issue is not related to the library

Comments

@aeon0
Copy link

aeon0 commented Oct 11, 2016

I get a segmentation fault when saving a json data object to a file like this:

#include <iostream>
#include <fstream>
#include "json.hpp"

bool SaveToFile(nlohmann::json data) {
    std::ofstream jsonFile;

    jsonFile.open("testFile.json" , std::ofstream::out | std::ofstream::trunc);
    jsonFile << data;
    jsonFile.close();

    return true;
}

int main() {
    std::cout << "========== Start Application ===========" << std::endl;

    return 0;
}

The problem is, I cant even debug anything. Because even if I don't use the function I get the segmentation fault.
When changing: jsonFile << data; to jsonFile << "Test String";, I dont get any errors.

I am using Visual GDB with gcc 4.9.2 (from here: http://gnutoolchains.com/raspberry/).

Please ask if any other information or clarification is needed!

@ChristophJud
Copy link
Contributor

ChristophJud commented Oct 11, 2016

I cannot reproduce it on a normal Ubuntu with a gcc 4.9.3. Must be something raspberrypi-specific. Can't you simply debug with the standard gdb and look at the backtrace after the program crashes?

@nlohmann
Copy link
Owner

Maybe @navybk can reproduce this on a Raspberry.

@aeon0
Copy link
Author

aeon0 commented Oct 11, 2016

Actually, It works on a raspberry. I just tried. There error occures on a odroid xu4.

@nlohmann
Copy link
Owner

Ok. Thanks!

@aeon0
Copy link
Author

aeon0 commented Oct 11, 2016

I guess this can be closed as I susspect even thou the error occures when using anything json related, it is not the real root of it.

@aeon0 aeon0 closed this as completed Oct 11, 2016
@nlohmann nlohmann added the solution: invalid the issue is not related to the library label Oct 12, 2016
@nlohmann
Copy link
Owner

Thanks for reporting anyway. If you can find anything more, I would be happy to have a look!

@aeon0
Copy link
Author

aeon0 commented Oct 25, 2016

Just in case of the very unlikely event that someone would run into the same problem in the future.
The error was because of Visual GDB (what exactly... I don't know). However what fixed the whole issue was upgrading from Ubuntu 15.10 to 16.04.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
solution: invalid the issue is not related to the library
Projects
None yet
Development

No branches or pull requests

3 participants