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