From a23cbe052da9949255036489d1f484afaeec0d3a Mon Sep 17 00:00:00 2001 From: jean-pierre charras Date: Wed, 4 Nov 2015 13:27:42 +0100 Subject: [PATCH] Opengl canvas: avoid hanging when the CACHED_CONTAINER is "out of memory" (which can happen which very large boards) and the vertex manager cannot allocate an other vertex: the message "Vertex allocation error" is now shown only once. the opengl canvas cannot show the full board, but at least the user can save the board, or switch to the legacy canvas. --- common/gal/opengl/vertex_manager.cpp | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/common/gal/opengl/vertex_manager.cpp b/common/gal/opengl/vertex_manager.cpp index e98df99fe8..d055b52169 100644 --- a/common/gal/opengl/vertex_manager.cpp +++ b/common/gal/opengl/vertex_manager.cpp @@ -51,12 +51,20 @@ VERTEX_MANAGER::VERTEX_MANAGER( bool aCached ) : void VERTEX_MANAGER::Vertex( GLfloat aX, GLfloat aY, GLfloat aZ ) const { + // flag to avoid hanging by calling DisplayError too many times: + static bool show_err = true; + // Obtain the pointer to the vertex in the currently used container VERTEX* newVertex = m_container->Allocate( 1 ); if( newVertex == NULL ) { - DisplayError( NULL, wxT( "Vertex allocation error" ) ); + if( show_err ) + { + DisplayError( NULL, wxT( "VERTEX_MANAGER::Vertex: Vertex allocation error" ) ); + show_err = false; + } + return; } @@ -66,12 +74,20 @@ void VERTEX_MANAGER::Vertex( GLfloat aX, GLfloat aY, GLfloat aZ ) const void VERTEX_MANAGER::Vertices( const VERTEX aVertices[], unsigned int aSize ) const { + // flag to avoid hanging by calling DisplayError too many times: + static bool show_err = true; + // Obtain pointer to the vertex in currently used container VERTEX* newVertex = m_container->Allocate( aSize ); if( newVertex == NULL ) { - DisplayError( NULL, wxT( "Vertex allocation error" ) ); + if( show_err ) + { + DisplayError( NULL, wxT( "VERTEX_MANAGER::Vertices: Vertex allocation error" ) ); + show_err = false; + } + return; }