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

segfault on rpi 3B+ asio standalone when calling start_accept #828

Open
FrankvdStam opened this issue Jun 16, 2019 · 2 comments
Open

segfault on rpi 3B+ asio standalone when calling start_accept #828

FrankvdStam opened this issue Jun 16, 2019 · 2 comments

Comments

@FrankvdStam
Copy link

FrankvdStam commented Jun 16, 2019

Full code here: https://github.com/FrankvdStam/Tempy

For reference, this project is supposed to be a temperature monitor. It sends my pc's temperature over to the pi, the pi draw's a graph with opengl.

Reproduction:
you need xorg-dev to run the program (opengl stuff)
bash gmake2_premake5.lua
make
run the binary in the bin directory

Init glfw and glad
libGL error: MESA-LOADER: failed to retrieve device information
MESA-LOADER: failed to retrieve device information
MESA-LOADER: failed to retrieve device information
Init glfw and glad end
Init websocket
Asio initialized
Message handler initialized
listen initialized
**Segmentation fault**

I traced it to the start_accept call in websocket's constructor:

websocket::websocket(received_callback callback)
{
    std::cout << "Init websocket" << std::endl; 
    try {
        m_server.init_asio();
        std::cout << "Asio initialized" << std::endl; 
        using websocketpp::lib::placeholders::_1;
        using websocketpp::lib::placeholders::_2;
        //m_server.set_message_handler(bind(&on_message, this, _1, _2));
        m_server.set_message_handler(*callback);
        std::cout << "Message handler initialized" << std::endl; 
        m_server.listen(9002);
        std::cout << "listen initialized" << std::endl; 
        m_server.start_accept();
        std::cout << "Start accept initialized" << std::endl; 
    }
    catch (std::exception e)
    {
        std::cout << "Failed to init websocket: " << e.what() << std::endl;
    }
    std::cout << "Init websocket end" << std::endl; 
}

I'm building on windows and on the pi, it runs without issue on windows. You can try windows by running vs2019_premake5.bat and opening in visual studio.

NOTE: I build premake5 from source. Runing these commands will run the binaries I made. You might want to build your own premake? Maybe the makefiles in the git repo are fine so you don't have to? Untrustworthy sources yadayada.

What am I doing wrong? I looked for issues but did not find anything which seemed relevant for me.

@FrankvdStam
Copy link
Author

FrankvdStam commented Jun 16, 2019

gdb gives me this:

Program received signal SIGSEGV, Segmentation fault.
0x0004027c in asio::detail::thread_info_base::allocate<asio::detail::thread_info_base::default_tag> (this_thread=0x1, size=92)
    at libraries/asio/include/asio/detail/thread_info_base.hpp:71
71	    if (this_thread && this_thread->reusable_memory_[Purpose::mem_index])

I have no idea what this means :)

Maybe I should ask over at the asio repo?

@FrankvdStam
Copy link
Author

FrankvdStam commented Jun 16, 2019

Since it was in a thread file or threading related construction, I tried constructing the websocket in the main function instead of outside of it. That does actually work. Problem solved I guess! I'll leave this issue open so someone can decide if any action should be taken.

Edit: putting it on the heap also works, that way I can define the pointer outside main, use it in methods, only construct it in main. I'm probably making a common mistake here, I'm not that experienced in C++.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant