Game Development Community

TGEA 1.7.0 Beta 2 Bug - Minor problem in GuiPopUpMenuCtrl

by Rene Damm · in Torque Game Engine Advanced · 03/29/2008 (4:05 pm) · 0 replies

This is only a really minor thing that will not cause any problems in release builds, but it will cause debug builds of the engine to bail with an assertion failure in certain situations.

The problem is that in GuiPopUpMenuCtrl::sort and GuiPopUpMenuCtrl::sortID the indexing operator of mEntries is used to take the address of the first element. If, however, there are no elements in the control (which to me seems kind of a strange situation given the nature of the control, but I had this happen multiple times in connection with the editor and so far haven't taken a more thorough look), the indexing operator will bail when assertions are enabled.

Be that as it may, the two methods can be easily changed to cope with the situation. Replace their code in guiPopUpMenuCtrl.cpp with:

//------------------------------------------------------------------------------
void GuiPopUpMenuCtrl::sort()
{
	S32 size = mEntries.size();
	if( size > 0 )
		dQsort( mEntries.address(), size, sizeof(Entry), textCompare);
}

//  Added to sort by entry ID
//------------------------------------------------------------------------------
void GuiPopUpMenuCtrl::sortID()
{
	S32 size = mEntries.size();
	if( size > 0 )
		dQsort( mEntries.address(), size, sizeof(Entry), idCompare);
}