Boost.Application
Boost.Application copied to clipboard
Windows, Hello World (server) crashes in release
I am trying to start a tiny service on my pc. And I copy the example provided in README entirely.
Then I use service_setup_ex.exe to register the service on my pc. The problem shows as soon as I click start the service.

Since I cannot debug a "server" mode app, I change the mode to "common". Then I found the crash happens at
my_log_file_ << "Start Log..." << std::endl;
It prompts to show an "Access Violation" exception.

But this only happens in release mode, not in debug mode.
Besides, I also have a try on the simple_server_example. The same problems happened.
Were you ever able to solve this?
@kirbyfan64 could you please confirm this issue on latest master?
Looks like it...if I build in debug instead, I get:
Assertion failed: px != 0, file C:\boost_1_65\boost/smart_ptr/shared_ptr.hpp, line 734
I'll check out a debugger for an actual traceback...
Traceback:
* thread #4, stop reason = breakpoint 1.3
frame #0: 0x5887ea40 ucrtbased.dll`abort
frame #1: 0x588830dd ucrtbased.dll`_get_wide_winmain_command_line + 7549
frame #2: 0x58882d89 ucrtbased.dll`_get_wide_winmain_command_line + 6697
frame #3: 0x5888142d ucrtbased.dll`_get_wide_winmain_command_line + 205
frame #4: 0x588833fa ucrtbased.dll`_wassert + 26
frame #5: 0x009ce493 simple_server_application.exe`boost::detail::win32::handle_manager::operator void *(void)const + 579
* frame #6: 0x009b1484 simple_server_application.exe
frame #7: 0x009b2234 simple_server_application.exe
frame #8: 0x009e70be simple_server_application.exe`void boost::thread::yield(void) + 7422
frame #9: 0x009e6fe0 simple_server_application.exe`void boost::thread::yield(void) + 7200
frame #10: 0x009e6e8d simple_server_application.exe`void boost::thread::yield(void) + 6861
frame #11: 0x009e7128 simple_server_application.exe`void boost::thread::yield(void) + 7528
frame #12: 0x76f48744 kernel32.dll`BaseThreadInitThunk + 36
frame #13: 0x7797582d ntdll.dll`RtlGetAppContainerNamedObjectPath + 253
frame #14: 0x779757fd ntdll.dll`RtlGetAppContainerNamedObjectPath + 205
Yes, this sucks, but I can't get lldb to read pdb info, and I'm still trying to get a Clang build working...
I tried the example from readme in common mode and it did not crash for me. (VS2015, VS2017)
Click to expand
#define BOOST_APPLICATION_FEATURE_NS_SELECT_BOOST
#include <iostream>
#include <fstream>
#include <boost/application.hpp>
using namespace boost;
// my application code
class myapp
{
public:
myapp(application::context& context)
: context_(context)
{
}
void worker()
{
// my application behaviour
// dump args
std::vector<std::string> arg_vector =
context_.find<application::args>()->arg_vector();
my_log_file_ << "-----------------------------" << std::endl;
my_log_file_ << "---------- Arg List ---------" << std::endl;
my_log_file_ << "-----------------------------" << std::endl;
// only print args on screen
for(std::vector<std::string>::iterator it = arg_vector.begin();
it != arg_vector.end(); ++it) {
my_log_file_ << *it << std::endl;
}
my_log_file_ << "-----------------------------" << std::endl;
// run logic
boost::shared_ptr<application::status> st =
context_.find<application::status>();
for(int count = 0; st->state() != application::status::stopped && count < 50; ++count)
{
boost::this_thread::sleep(boost::posix_time::milliseconds(100));
if(st->state() == application::status::paused)
my_log_file_ << count << ", paused..." << std::endl;
else
my_log_file_ << count << ", running..." << std::endl;
}
}
// param
int operator()()
{
std::string logfile
= context_.find<application::path>()->executable_path().string() + "/log.txt";
my_log_file_.open(logfile.c_str());
my_log_file_ << "Start Log..." << std::endl;
#if 0
// launch a work thread
*boost::thread thread(&myapp::worker, this);
context_.find<application::wait_for_termination_request>()->wait();
#else
// to run direct
worker();
#endif
return 0;
}
// windows/posix
bool stop()
{
my_log_file_ << "Stoping my application..." << std::endl;
my_log_file_.close();
return true; // return true to stop, false to ignore
}
// windows specific (ignored on posix)
bool pause()
{
my_log_file_ << "Pause my application..." << std::endl;
return true; // return true to pause, false to ignore
}
bool resume()
{
my_log_file_ << "Resume my application..." << std::endl;
return true; // return true to resume, false to ignore
}
private:
std::ofstream my_log_file_;
application::context& context_;
};
int main(int argc, char *argv[])
{
application::context app_context;
// auto_handler will automatically add termination, pause and resume (windows) handlers
application::auto_handler<myapp> app(app_context);
// my server aspects
// to handle args
app_context.insert<application::args>(
boost::make_shared<application::args>(argc, argv));
// my server instantiation
boost::system::error_code ec;
int result = application::launch<application::common/*server*/>(app, app_context, ec);
if(ec)
{
std::cout << "[E] " << ec.message()
<< " <" << ec.value() << "> " << std::endl;
}
return result;
}