Catch access violation in defragment due to OpenGL drivers on Windows.
This commit is contained in:
parent
d1f6ba77e8
commit
74a242c662
|
@ -40,6 +40,10 @@
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
|
|
||||||
|
#ifdef __WIN32__
|
||||||
|
#include <excpt.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef KICAD_GAL_PROFILE
|
#ifdef KICAD_GAL_PROFILE
|
||||||
#include <wx/log.h>
|
#include <wx/log.h>
|
||||||
#include <profile.h>
|
#include <profile.h>
|
||||||
|
@ -275,29 +279,42 @@ void CACHED_CONTAINER::defragment( VERTEX* aTarget )
|
||||||
ITEMS::iterator it, it_end;
|
ITEMS::iterator it, it_end;
|
||||||
int newOffset = 0;
|
int newOffset = 0;
|
||||||
|
|
||||||
for( VERTEX_ITEM* item : m_items )
|
#ifdef __WIN32__
|
||||||
|
__try
|
||||||
|
#endif
|
||||||
{
|
{
|
||||||
int itemOffset = item->GetOffset();
|
for( VERTEX_ITEM* item : m_items )
|
||||||
int itemSize = item->GetSize();
|
{
|
||||||
|
int itemOffset = item->GetOffset();
|
||||||
|
int itemSize = item->GetSize();
|
||||||
|
|
||||||
// Move an item to the new container
|
// Move an item to the new container
|
||||||
memcpy( &aTarget[newOffset], &m_vertices[itemOffset], itemSize * VERTEX_SIZE );
|
memcpy( &aTarget[newOffset], &m_vertices[itemOffset], itemSize * VERTEX_SIZE );
|
||||||
|
|
||||||
// Update new offset
|
// Update new offset
|
||||||
item->setOffset( newOffset );
|
item->setOffset( newOffset );
|
||||||
|
|
||||||
// Move to the next free space
|
// Move to the next free space
|
||||||
newOffset += itemSize;
|
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__
|
||||||
// Move the current item and place it at the end
|
__except( GetExceptionCode() == STATUS_ACCESS_VIOLATION ? EXCEPTION_EXECUTE_HANDLER
|
||||||
if( m_item->GetSize() > 0 )
|
: EXCEPTION_CONTINUE_SEARCH )
|
||||||
{
|
{
|
||||||
memcpy( &aTarget[newOffset], &m_vertices[m_item->GetOffset()],
|
throw std::runtime_error( "Access violation in defragment. This is usually an indicator of "
|
||||||
m_item->GetSize() * VERTEX_SIZE );
|
"system or GPU memory running low." );
|
||||||
m_item->setOffset( newOffset );
|
};
|
||||||
m_chunkOffset = newOffset;
|
#endif
|
||||||
}
|
|
||||||
|
|
||||||
m_maxIndex = usedSpace();
|
m_maxIndex = usedSpace();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue