Move __try into lambda.
This commit is contained in:
parent
b913e9be1e
commit
525d0da126
|
@ -275,48 +275,52 @@ bool CACHED_CONTAINER::reallocate( unsigned int aSize )
|
||||||
|
|
||||||
void CACHED_CONTAINER::defragment( VERTEX* aTarget )
|
void CACHED_CONTAINER::defragment( VERTEX* aTarget )
|
||||||
{
|
{
|
||||||
#ifdef __WIN32__
|
// Defragmentation
|
||||||
__try
|
ITEMS::iterator it, it_end;
|
||||||
#endif
|
int newOffset = 0;
|
||||||
|
|
||||||
|
[&]()
|
||||||
{
|
{
|
||||||
// Defragmentation
|
|
||||||
ITEMS::iterator it, it_end;
|
|
||||||
int newOffset = 0;
|
|
||||||
|
|
||||||
for( VERTEX_ITEM* item : m_items )
|
|
||||||
{
|
|
||||||
int itemOffset = item->GetOffset();
|
|
||||||
int itemSize = item->GetSize();
|
|
||||||
|
|
||||||
// Move an item to the new container
|
|
||||||
memcpy( &aTarget[newOffset], &m_vertices[itemOffset], itemSize * VERTEX_SIZE );
|
|
||||||
|
|
||||||
// Update new offset
|
|
||||||
item->setOffset( newOffset );
|
|
||||||
|
|
||||||
// Move to the next free space
|
|
||||||
newOffset += itemSize;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Move the current item and place it at the end
|
|
||||||
if( m_item->GetSize() > 0 )
|
|
||||||
{
|
|
||||||
memcpy( &aTarget[newOffset], &m_vertices[m_item->GetOffset()],
|
|
||||||
m_item->GetSize() * VERTEX_SIZE );
|
|
||||||
m_item->setOffset( newOffset );
|
|
||||||
m_chunkOffset = newOffset;
|
|
||||||
}
|
|
||||||
|
|
||||||
m_maxIndex = usedSpace();
|
|
||||||
}
|
|
||||||
#ifdef __WIN32__
|
#ifdef __WIN32__
|
||||||
__except( GetExceptionCode() == STATUS_ACCESS_VIOLATION ? EXCEPTION_EXECUTE_HANDLER
|
__try
|
||||||
: EXCEPTION_CONTINUE_SEARCH )
|
|
||||||
{
|
|
||||||
throw std::runtime_error( "Access violation in defragment. This is usually an indicator of "
|
|
||||||
"system or GPU memory running low." );
|
|
||||||
};
|
|
||||||
#endif
|
#endif
|
||||||
|
{
|
||||||
|
for( VERTEX_ITEM* item : m_items )
|
||||||
|
{
|
||||||
|
int itemOffset = item->GetOffset();
|
||||||
|
int itemSize = item->GetSize();
|
||||||
|
|
||||||
|
// Move an item to the new container
|
||||||
|
memcpy( &aTarget[newOffset], &m_vertices[itemOffset], itemSize * VERTEX_SIZE );
|
||||||
|
|
||||||
|
// Update new offset
|
||||||
|
item->setOffset( newOffset );
|
||||||
|
|
||||||
|
// Move to the next free space
|
||||||
|
newOffset += itemSize;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Move the current item and place it at the end
|
||||||
|
if( m_item->GetSize() > 0 )
|
||||||
|
{
|
||||||
|
memcpy( &aTarget[newOffset], &m_vertices[m_item->GetOffset()],
|
||||||
|
m_item->GetSize() * VERTEX_SIZE );
|
||||||
|
m_item->setOffset( newOffset );
|
||||||
|
m_chunkOffset = newOffset;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#ifdef __WIN32__
|
||||||
|
__except( GetExceptionCode() == STATUS_ACCESS_VIOLATION ? EXCEPTION_EXECUTE_HANDLER
|
||||||
|
: EXCEPTION_CONTINUE_SEARCH )
|
||||||
|
{
|
||||||
|
throw std::runtime_error(
|
||||||
|
"Access violation in defragment. This is usually an indicator of "
|
||||||
|
"system or GPU memory running low." );
|
||||||
|
};
|
||||||
|
#endif
|
||||||
|
}();
|
||||||
|
|
||||||
|
m_maxIndex = usedSpace();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue