Segmentation fault on std::sort

Started by
10 comments, last by Red Ant 11 years, 12 months ago
Hi Red Ant, thanks for your respons.

See, that was what I thought as well, as you can see from what I said in my original post:

[background=rgb(250, 251, 252)]So, as you can see the compare function gets called with valid memory adresses (i think?) but the get_f() (method used for comparison) gets caleld by 0x0 (NULL pointer?)[/background]


[/quote]

But then why does it work when I change nothing but the sort to stable_sort? Since the operands are still the same..

I got everything to work just fine though.. And now, after some optimization I am no longer using any sorting method at all, but rather putting objects in the vector in order already on insertion, with this bit of code:



void Logic::push_searchCell(std::vector<std::shared_ptr<SearchCell> > &v, std::shared_ptr<SearchCell> &a)
{
if (v.size() == 0)
{
v.push_back(a);
return;
}

v.insert(v.begin() + sort_searchCells(v, 0, v.size() - 1, a->get_f()), a);
}

//Find an element in vector v by a chosen value via binary search
const short int Logic::sort_searchCells(std::vector<std::shared_ptr<SearchCell> > &v, int start, int stop, int numb)
{
if (start > stop)
{
return start;
}

int mid = (start + stop)/2;

if (numb < v.at(mid)->get_f())
{
return sort_searchCells(v, start, mid-1, numb);
}
else
{
return sort_searchCells(v, mid+1, stop, numb);
}
}


Saved me a few ms on each call to find path and solved any future ?-marks regarding the sorting =)
Advertisement
Oops, sorry. Shame on me for not reading the whole thread before posting. sleep.png

This topic is closed to new replies.

Advertisement