Commit 8c32bf06 authored by Gargaj's avatar Gargaj
Browse files

only save shader after successful frame render

parent f86674e7
...@@ -356,6 +356,7 @@ int main(int argc, char *argv[]) ...@@ -356,6 +356,7 @@ int main(int argc, char *argv[])
float fNextTick = 0.1; float fNextTick = 0.1;
while (!Renderer::WantsToQuit()) while (!Renderer::WantsToQuit())
{ {
bool newShader = false;
float time = Timer::GetTime() / 1000.0; // seconds float time = Timer::GetTime() / 1000.0; // seconds
Renderer::StartFrame(); Renderer::StartFrame();
...@@ -404,17 +405,9 @@ int main(int argc, char *argv[]) ...@@ -404,17 +405,9 @@ int main(int argc, char *argv[])
mShaderEditor.GetText(szShader,65535); mShaderEditor.GetText(szShader,65535);
if (Renderer::ReloadShader( szShader, strlen(szShader), szError, 4096 )) if (Renderer::ReloadShader( szShader, strlen(szShader), szError, 4096 ))
{ {
FILE * f = fopen(Renderer::defaultShaderFilename,"wb"); // Shader compilation successful; we set a flag to save if the frame render was successful
if (f) // (If there is a driver crash, don't save.)
{ newShader = true;
fwrite( szShader, strlen(szShader), 1, f );
fclose(f);
mDebugOutput.SetText( "" );
}
else
{
mDebugOutput.SetText( "Unable to save shader! Your work will be lost when you quit!" );
}
} }
else else
{ {
...@@ -430,12 +423,12 @@ int main(int argc, char *argv[]) ...@@ -430,12 +423,12 @@ int main(int argc, char *argv[])
bool consumed = false; bool consumed = false;
if (Renderer::keyEventBuffer[i].scanCode) if (Renderer::keyEventBuffer[i].scanCode)
{ {
mShaderEditor.KeyDown( mShaderEditor.KeyDown(
iswalpha(Renderer::keyEventBuffer[i].scanCode) ? towupper(Renderer::keyEventBuffer[i].scanCode) : Renderer::keyEventBuffer[i].scanCode, iswalpha(Renderer::keyEventBuffer[i].scanCode) ? towupper(Renderer::keyEventBuffer[i].scanCode) : Renderer::keyEventBuffer[i].scanCode,
Renderer::keyEventBuffer[i].shift, Renderer::keyEventBuffer[i].shift,
Renderer::keyEventBuffer[i].ctrl, Renderer::keyEventBuffer[i].ctrl,
Renderer::keyEventBuffer[i].alt, Renderer::keyEventBuffer[i].alt,
&consumed); &consumed);
} }
if (!consumed && Renderer::keyEventBuffer[i].character) if (!consumed && Renderer::keyEventBuffer[i].character)
{ {
...@@ -538,6 +531,22 @@ int main(int argc, char *argv[]) ...@@ -538,6 +531,22 @@ int main(int argc, char *argv[])
Renderer::EndFrame(); Renderer::EndFrame();
Capture::CaptureFrame(); Capture::CaptureFrame();
if (newShader)
{
// Frame render successful, save shader
FILE * f = fopen(Renderer::defaultShaderFilename,"wb");
if (f)
{
fwrite( szShader, strlen(szShader), 1, f );
fclose(f);
mDebugOutput.SetText( "" );
}
else
{
mDebugOutput.SetText( "Unable to save shader! Your work will be lost when you quit!" );
}
}
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment