load list item in thread.And then error [vector.h(404) assert "idx < m_size" failed in at().] has occurred.

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
kou
In need of some credit
In need of some credit
Posts: 3
Joined: Tue Nov 28, 2017 12:40 am

load list item in thread.And then error [vector.h(404) assert "idx < m_size" failed in at().] has occurred.

Post by kou » Tue Nov 28, 2017 1:48 am

I use class wxTreeListCtrl to make the list.And load list item within function AppendItem.
But it's spent a lot of time when list item is too large.
So I try to load part of the list item use wxThread.
But when I load item in thread ,then error [......vector.h(404) assert "idx < m_size" failed in at().] has occurred.

And here is my code.

Code: Select all

wxThread::ExitCode XXCtrlThread::Entry()
{
	while (TestDestroy())
	{
		return NULL;
	}
	m_pHandler->LoadXXList();
	return (wxThread::ExitCode)0;     // success
}
.
.
.
vector<wxTreeListItem> tmp_items;
vector<vector<int>> tmp_keys;
.
.
.
void XXListCtrl::LoadXXList()
{
	for(size_t i = 0; i < tmp_items.size();i++)
	{
		wxString text;
		for(size_t j = 5000;j<tmp_keys[i].size();j++)
		{
			text<<tmp_keys[i][j];
			AppendItem(tmp_items[i],text);
			text.clear();
		}
	}
}
Is any one know the reason,thank you.
Or how to be quickly load list item when list item is too large.
Attachments
2017-11-28 10_16_42-wxWidgets Debug Alert.png
2017-11-28 10_16_42-wxWidgets Debug Alert.png (7.21 KiB) Viewed 482 times

User avatar
doublemax
Moderator
Moderator
Posts: 14176
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: load list item in thread.And then error [vector.h(404) assert "idx < m_size" failed in at().] has occurred.

Post by doublemax » Tue Nov 28, 2017 4:03 pm

You should not access GUI elements from a worker thread.
Use the source, Luke!

kou
In need of some credit
In need of some credit
Posts: 3
Joined: Tue Nov 28, 2017 12:40 am

Re: load list item in thread.And then error [vector.h(404) assert "idx < m_size" failed in at().] has occurred.

Post by kou » Wed Nov 29, 2017 12:18 am

doublemax wrote:You should not access GUI elements from a worker thread.
Thank you.
So is there any way to speed up loading list?

User avatar
doublemax
Moderator
Moderator
Posts: 14176
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: load list item in thread.And then error [vector.h(404) assert "idx < m_size" failed in at().] has occurred.

Post by doublemax » Wed Nov 29, 2017 7:01 am

As wxTreeListCtrl has no method to add multiple items at once, i can't think of any way to speed this up.

If you want to avoid locking up the GUI, you could add the items in small chunks in a timer event.
Use the source, Luke!

PB
Part Of The Furniture
Part Of The Furniture
Posts: 2066
Joined: Sun Jan 03, 2010 5:45 pm

Re: load list item in thread.And then error [vector.h(404) assert "idx < m_size" failed in at().] has occurred.

Post by PB » Wed Nov 29, 2017 8:29 am

Another common way used in such situations with tree controls is, if possible, to add the items to individual nodes only when the node is being expanded for the first time. This may take a bit more effort to implement but it is not difficult. This could be combined with doublemaxes suggestion too...

User avatar
xaviou
Super wx Problem Solver
Super wx Problem Solver
Posts: 429
Joined: Mon Aug 21, 2006 3:18 pm
Location: Annecy - France
Contact:

Re: load list item in thread.And then error [vector.h(404) assert "idx < m_size" failed in at().] has occurred.

Post by xaviou » Wed Nov 29, 2017 8:40 am

Hi
kou wrote:So is there any way to speed up loading list?
You can try "Freeze()" and "Thaw()" on your wxTreeListCtrl respectively before and after adding your items to it.
It can really speed-up the process (but perhaps it isn't enough : give it a try).

Another way would be to add the items in 2 times :
  • A first function that will add a few items (to have a quickly filled control for the user)
  • Then a timer adding the others items step by step
Regards
Xav'
My wxWidgets stuff web page : [email protected]'s wxStuff

Post Reply