From dcf331a78df440e6c0e1c6360c67321368d97749 Mon Sep 17 00:00:00 2001 From: Thomas Krijnen Date: Mon, 9 Oct 2017 15:43:51 +0200 Subject: [PATCH] Correct instance lookup --- src/ifcparse/IfcHdf5File.cpp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/ifcparse/IfcHdf5File.cpp b/src/ifcparse/IfcHdf5File.cpp index d0f7de7e04..d23971d95d 100644 --- a/src/ifcparse/IfcHdf5File.cpp +++ b/src/ifcparse/IfcHdf5File.cpp @@ -364,7 +364,15 @@ public: const std::vector& insts = instances(t); - auto it = std::lower_bound(insts.begin(), insts.end(), v); + auto it = std::lower_bound(insts.begin(), insts.end(), v, [](IfcUtil::IfcBaseClass* other, IfcUtil::IfcBaseClass* val) { + // An ordering based on ID is not equivalent to an ordering based on pointer address! + return other->data().id() < val->data().id(); + }); + + if (it == insts.end()) { + throw std::runtime_error("Unable to find instance"); + } + b = std::distance(insts.begin(), it); return std::make_pair(a, b);