@@ -1725,90 +1725,102 @@ void GLShaderManager::PrintShaderSource( Str::StringRef programName, GLuint obje
17251725 std::string delim ( " \n " );
17261726 std::string src ( dump );
17271727
1728- ri.Hunk_FreeTempMemory ( dump );
1728+ try {
1729+ int lineNumber = 0 ;
1730+ size_t pos = 0 ;
17291731
1730- int lineNumber = 0 ;
1731- size_t pos = 0 ;
1732+ int infoLogID = -1 ;
1733+ if ( infoLog.size () > 0 ) {
1734+ infoLogID = 0 ;
1735+ }
17321736
1733- int infoLogID = -1 ;
1734- if ( infoLog.size () > 0 ) {
1735- infoLogID = 0 ;
1736- }
1737+ while ( ( pos = src.find ( delim ) ) != std::string::npos ) {
1738+ std::string line = src.substr ( 0 , pos );
1739+ if ( Str::IsPrefix ( " #line " , line ) )
1740+ {
1741+ size_t lineNumEnd = line.find ( ' ' , 6 );
1742+ Str::ParseInt ( lineNumber, line.substr ( 6 , lineNumEnd - 6 ) );
1743+ }
17371744
1738- while ( ( pos = src.find ( delim ) ) != std::string::npos ) {
1739- std::string line = src.substr ( 0 , pos );
1740- if ( Str::IsPrefix ( " #line " , line ) )
1741- {
1742- size_t lineNumEnd = line.find ( ' ' , 6 );
1743- Str::ParseInt ( lineNumber, line.substr ( 6 , lineNumEnd - 6 ) );
1744- }
1745+ std::string number = std::to_string ( lineNumber );
17451746
1746- std::string number = std::to_string ( lineNumber );
1747+ static const int numberWidth = 4 ;
1748+ int p = numberWidth - number.length ();
1749+ p = p < 0 ? 0 : p;
1750+ number.insert ( number.begin (), p, ' ' );
17471751
1748- static const int numberWidth = 4 ;
1749- int p = numberWidth - number. length ( );
1750- p = p < 0 ? 0 : p ;
1751- number. insert ( number. begin (), p, ' ' );
1752+ buffer. append ( number ) ;
1753+ buffer. append ( " : " );
1754+ buffer. append ( line ) ;
1755+ buffer. append ( delim );
17521756
1753- buffer. append ( number );
1754- buffer. append ( " : " );
1755- buffer.append ( line );
1756- buffer. append ( delim );
1757+ while ( infoLogID != - 1 && infoLog[infoLogID]. line == lineNumber ) {
1758+ if ( ( int ( line. length () ) > infoLog[infoLogID]. character ) && ( infoLog[infoLogID]. character != - 1 ) ) {
1759+ buffer.append ( numberWidth + 2 , ' - ' );
1760+ const size_t position = line. find_first_not_of ( " \t " );
17571761
1758- while ( infoLogID != -1 && infoLog[infoLogID].line == lineNumber ) {
1759- if ( ( int ( line.length () ) > infoLog[infoLogID].character ) && ( infoLog[infoLogID].character != -1 ) ) {
1760- buffer.append ( numberWidth + 2 , ' -' );
1761- const size_t position = line.find_first_not_of ( " \t " );
1762+ if ( position != std::string::npos ) {
1763+ buffer.append ( position, ' \t ' );
1764+ buffer.append ( infoLog[infoLogID].character - position, ' -' );
1765+ } else {
1766+ buffer.append ( infoLog[infoLogID].character , ' -' );
1767+ }
1768+ buffer.append ( " ^" );
1769+ buffer.append ( line.length () - infoLog[infoLogID].character - 1 , ' -' );
17621770
1763- if ( position != std::string::npos ) {
1764- buffer.append ( position, ' \t ' );
1765- buffer.append ( infoLog[infoLogID].character - position, ' -' );
1766- } else {
1767- buffer.append ( infoLog[infoLogID].character , ' -' );
1768- }
1769- buffer.append ( " ^" );
1770- buffer.append ( line.length () - infoLog[infoLogID].character - 1 , ' -' );
1771+ } else if ( ( line.length () > 0 ) && ( infoLog[infoLogID].token .length () > 0 ) ) {
1772+ size_t position = line.find_first_not_of ( " \t " );
1773+ size_t prevPosition = 0 ;
17711774
1772- } else if ( ( line.length () > 0 ) && ( infoLog[infoLogID].token .length () > 0 ) ) {
1773- size_t position = line.find_first_not_of ( " \t " );
1774- size_t prevPosition = 0 ;
1775+ buffer.append ( numberWidth + 2 , ' -' );
1776+ if ( position != std::string::npos ) {
1777+ buffer.append ( position, ' \t ' );
1778+ } else {
1779+ position = 0 ;
1780+ }
17751781
1776- buffer.append ( numberWidth + 2 , ' -' );
1777- if ( position != std::string::npos ) {
1778- buffer.append ( position, ' \t ' );
1782+ while ( ( position = line.find ( infoLog[infoLogID].token , position ) ) && ( position != std::string::npos ) ) {
1783+ buffer.append ( position - prevPosition - 1 , ' -' );
1784+ buffer.append ( " ^" );
1785+ prevPosition = position;
1786+ position++;
1787+ }
1788+ buffer.append ( line.length () - position - 1 , ' -' );
17791789 } else {
1780- position = 0 ;
1790+ buffer. append ( numberWidth + 2 + line. length (), ' ^ ' ) ;
17811791 }
17821792
1783- while ( ( position = line.find ( infoLog[infoLogID].token , position ) ) && ( position != std::string::npos ) ) {
1784- buffer.append ( position - prevPosition - 1 , ' -' );
1785- buffer.append ( " ^" );
1786- prevPosition = position;
1787- position++;
1793+ buffer.append ( delim );
1794+ buffer.append ( infoLog[infoLogID].error );
1795+ buffer.append ( delim );
1796+ buffer.append ( delim );
1797+
1798+ infoLogID++;
1799+
1800+ if ( infoLogID >= int ( infoLog.size () ) ) {
1801+ infoLogID = -1 ;
17881802 }
1789- buffer.append ( line.length () - position - 1 , ' -' );
1790- } else {
1791- buffer.append ( numberWidth + 2 + line.length (), ' ^' );
17921803 }
17931804
1794- buffer.append ( delim );
1795- buffer.append ( infoLog[infoLogID].error );
1796- buffer.append ( delim );
1797- buffer.append ( delim );
1798-
1799- infoLogID++;
1805+ src.erase ( 0 , pos + delim.length () );
18001806
1801- if ( infoLogID >= int ( infoLog.size () ) ) {
1802- infoLogID = -1 ;
1803- }
1807+ lineNumber++;
18041808 }
18051809
1806- src.erase ( 0 , pos + delim.length () );
1807-
1808- lineNumber++;
1810+ Log::Warn (" Source for shader program %s:\n %s" , programName, buffer);
1811+ }
1812+ catch (std::exception& err)
1813+ {
1814+ Log::Warn (" Exception occurred when processing the source for shader program %s (%s): %s" , programName, typeid (err).name (), err.what () );
1815+ Log::Warn (" Raw source for shader program %s:\n %s" , programName, dump);
1816+ }
1817+ catch (...)
1818+ {
1819+ Log::Warn (" Unknown exception occurred when processing the source for shader program %s." , programName);
1820+ Log::Warn (" Raw source for shader program %s:\n %s" , programName, dump);
18091821 }
18101822
1811- Log::Warn ( " Source for shader program %s: \n %s " , programName, buffer. c_str () );
1823+ ri. Hunk_FreeTempMemory ( dump );
18121824}
18131825
18141826std::vector<GLShaderManager::InfoLogEntry> GLShaderManager::ParseInfoLog ( const std::string& infoLog ) const {
0 commit comments