Fixed mysterious ASAN crash in conflict detection code

This commit is contained in:
Lukas Matena 2023-04-27 14:52:26 +02:00
parent 0f15eb6600
commit 720ddf73da
2 changed files with 9 additions and 8 deletions

View File

@ -91,19 +91,18 @@ inline Grids line_rasterization(const Line &line, int64_t xdist = RasteXDistance
void LinesBucketQueue::emplace_back_bucket(std::vector<ExtrusionPaths> &&paths, const void *objPtr, Point offset) void LinesBucketQueue::emplace_back_bucket(std::vector<ExtrusionPaths> &&paths, const void *objPtr, Point offset)
{ {
auto oldSize = _buckets.capacity();
if (_objsPtrToId.find(objPtr) == _objsPtrToId.end()) { if (_objsPtrToId.find(objPtr) == _objsPtrToId.end()) {
_objsPtrToId.insert({objPtr, _objsPtrToId.size()}); _objsPtrToId.insert({objPtr, _objsPtrToId.size()});
_idToObjsPtr.insert({_objsPtrToId.size() - 1, objPtr}); _idToObjsPtr.insert({_objsPtrToId.size() - 1, objPtr});
} }
_buckets.emplace_back(std::move(paths), _objsPtrToId[objPtr], offset); _buckets.emplace_back(std::move(paths), _objsPtrToId[objPtr], offset);
_pq.push(&_buckets.back()); }
auto newSize = _buckets.capacity();
if (oldSize != newSize) { // pointers change void LinesBucketQueue::build_queue()
decltype(_pq) newQueue; {
for (LinesBucket &bucket : _buckets) { newQueue.push(&bucket); } assert(_pq.empty);
std::swap(_pq, newQueue); for (LinesBucket &bucket : _buckets)
} _pq.push(&bucket);
} }
double LinesBucketQueue::removeLowests() double LinesBucketQueue::removeLowests()
@ -218,6 +217,7 @@ ConflictResultOpt ConflictChecker::find_inter_of_lines_in_diff_objs(PrintObjectP
conflictQueue.emplace_back_bucket(std::move(layers.first), obj, obj->instances().front().shift); conflictQueue.emplace_back_bucket(std::move(layers.first), obj, obj->instances().front().shift);
conflictQueue.emplace_back_bucket(std::move(layers.second), obj, obj->instances().front().shift); conflictQueue.emplace_back_bucket(std::move(layers.second), obj, obj->instances().front().shift);
} }
conflictQueue.build_queue();
std::vector<LineWithIDs> layersLines; std::vector<LineWithIDs> layersLines;
std::vector<double> heights; std::vector<double> heights;

View File

@ -78,6 +78,7 @@ private:
public: public:
void emplace_back_bucket(std::vector<ExtrusionPaths> &&paths, const void *objPtr, Point offset); void emplace_back_bucket(std::vector<ExtrusionPaths> &&paths, const void *objPtr, Point offset);
void build_queue();
bool valid() const { return _pq.empty() == false; } bool valid() const { return _pq.empty() == false; }
const void *idToObjsPtr(int id) const void *idToObjsPtr(int id)
{ {