Skip to content

Commit

Permalink
Making #include handling in shaders more robust
Browse files Browse the repository at this point in the history
Doesn't crash when shaders use multiple files and will search nearby
directories when looking for a shader include.
  • Loading branch information
imccown committed Jan 16, 2016
1 parent 1bf4cd7 commit 712ed62
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 8 deletions.
44 changes: 36 additions & 8 deletions DissectorGUI/shaderdebugwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,17 @@ void ShaderDebugWindow::ProcessInputData( MainWindow* iMain, char* iData, size_t
QString str = QString::fromLocal8Bit( iter, size );
iter += size;
mFilenames.push_back( str );

// Only the base filename is a full path, need to try to complete other filenames from that path
if( str.length() >= 2 && str[1] == ':' ) {
std::string path = str.toLocal8Bit();
size_t findpos = path.rfind( '\\' );
if( findpos != std::string::npos ) {
path = path.substr( 0, findpos+1 );
mIncludeDirectories.push_back( path );
mIncludeDirectories.push_back( path + "Include\\" );
}
}
}

for( int ii = 0; ii < hdr.mNumVariables; ++ii )
Expand Down Expand Up @@ -179,15 +190,32 @@ void ShaderDebugWindow::GotoCurrentLine()
{
char buffer[1024];
size_t readSize = 1;
text->clear();

QTextCursor cursor = text->textCursor();
cursor.setCharFormat( mDefaultTextFormat );
cursor.clearSelection();
text->setTextCursor( cursor );

FILE* f;
fopen_s( &f, mFilenames[ step.mFilename ].toLocal8Bit(), "r" );
while( f && readSize )
{
readSize = fread( buffer, 1, 1023, f );
buffer[readSize] = 0;
text->insertPlainText( QString( buffer ) );
int includeIter = 0;
while( !f ) {
fopen_s( &f, (mIncludeDirectories[includeIter] + mFilenames[ step.mFilename ].toLocal8Bit().data() ).c_str(), "r" );
includeIter++;
}
if( f ) {

while( readSize )
{
readSize = fread( buffer, 1, 1023, f );
buffer[readSize] = 0;
text->insertPlainText( QString( buffer ) );
}
fclose( f );
} else {
text->insertPlainText( QString( "Couldn't Load File %1" ).arg( mFilenames[ step.mFilename ] ) );
}
fclose( f );

text->setReadOnly( true );
mCurrentFile = step.mFilename;
Expand Down Expand Up @@ -347,7 +375,7 @@ void ShaderDebugWindow::CreateAnalyzeListing()
if( step.mFilename >= 0 && step.mFilename < mFilenames.size() )
{
line += mFilenames[ step.mFilename ];
line += QString("%1").arg(step.mLine);
line += QString("").arg(step.mLine);
mListing.push_back( line );
}
}
Expand All @@ -370,7 +398,7 @@ void ShaderDebugWindow::CreateStepList( QVector<QString>& iFileLineList,
if( step.mFilename >= 0 && step.mFilename < mFilenames.size() )
{
QString stepLine = mFilenames[ step.mFilename ];
stepLine += QString("%1").arg(step.mLine);
stepLine += QString("").arg(step.mLine);
if( QString::compare( stepLine, line ) == 0 )
{
matchNum = jj;
Expand Down
1 change: 1 addition & 0 deletions DissectorGUI/shaderdebugwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ private slots:
void GetVariableReports( QVector<VariableReport>& oVars );

QVector< QString > mFilenames;
QVector< std::string > mIncludeDirectories;
QVector< VariableEntry > mVariables;
QVector< DebugStep > mSteps;

Expand Down
Binary file modified bin/DissectorGUI.exe
Binary file not shown.

0 comments on commit 712ed62

Please sign in to comment.