Skip to main content
GameDev.net gamedev.net
🔒 Locked

Assignment operator/copy constructor issue with Boost.Function

Started by Craig_jb Jun 7, 2012 at 10:09 PM 0 replies 2.9k views
Original Post
Craig_jb
Craig_jb
I've scoured the internet for hours on this one and still cannot figure it out! Any help is appreciated.


typedef boost::function<void ()> TaskKernel;
void TaskScheduler::pushTask(const TaskData& taskData, TaskKernel kernel)
{
Task* task = m_taskPool->obtain();
task->m_kernel = TaskKernel(kernel);
task->m_taskData = taskData;
}
// later in the calling code
sch->pushTask(TaskData(), boost::bind(&run);


I get an EXC_BAD_ACCESS in boost move_assign function for the copy constructor or operator= every time. I tried passing the function without boost::bind and with all different variations. No luck...

Is there a special technique I am missing for passing boost::functions around?
the_edd
the_edd
Perhaps try changing this:


// task->m_kernel = TaskKernel(kernel);
task->m_kernel = kernel;


I haven't looked at the latest code for boost::function, but if it's doing move-emulation for your non-C++11 compiler, that might be causing trouble. If you really need the extra copy, try copying it to a named temporary prior to the assignment (making the source of the assignment an l-value).

EDIT: perhaps you also intended to use pass-by-const-reference for the 'kernel' argument in pushTask()? Though I don't think that will cause this problem.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.