Project

General

Profile

Bug #9678

Crash in Wt::Dbo if we clear a collection and add an item.

Added by Tomaz Canabrava 5 months ago. Updated 5 months ago.

Status:
New
Priority:
Normal
Assignee:
-
Target version:
-
Start date:
01/28/2022
Due date:
% Done:

0%

Estimated time:

Description

The following code crashes:

template
void reduceCollectionToOne(Wt::Dbo::collectionWt::Dbo::ptr<TYPE>& collection,
const Wt::Dbo::ptr& one)
{
colleciton.clear();
collection.insert(one)

}

The following code works.

template
void reduceCollectionToOne(Wt::Dbo::collectionWt::Dbo::ptr<TYPE>& collection,
const Wt::Dbo::ptr& one)
for (const Wt::Dbo::ptr& element : collection) {
if (element != one) {
collection.erase(element);
}
}
}

#1

Updated by Tomaz Canabrava 5 months ago

The following code crashes deep into Wt.
Wt version 4.6.0

template <class TYPE>
void reduceCollectionToOne(Wt::Dbo::collection<Wt::Dbo::ptr<TYPE>>& collection,
                           const Wt::Dbo::ptr<TYPE>& one)
{
    collection.clear();
    collection.insert(one);
}

#2

Updated by Korneel Dumon 5 months ago

I tried your function using the feature/dbo/tutorial2 example and it worked. I don't know what's going wrong for you, but you could check if the ptr argument is added to the session and if there is an active transaction.

Also available in: Atom PDF