When executing python scripts temporarily catch exceptions in renderer

* Errors like syntax and runtime errors in python are thrown as
  exceptions. So for when we invoke onto the renderer thread to do some
  work, we need to be able to catch those exceptions otherwise the whole
  program dies. So over the execute, temporarily switch the thread into
  a catching-exception mode, which then gets rethrown on the invoker's
  thread.
* Note that BeginInvoke shouldn't be used by python since the callback
  might happen after the execution has finished (there's no way to wait
  at the moment).
This commit is contained in:
baldurk
2015-03-29 19:59:40 +01:00
parent c0be5552e8
commit 8b9caa6cc2
2 changed files with 33 additions and 1 deletions
+29 -1
View File
@@ -52,6 +52,7 @@ namespace renderdocui.Code
public InvokeMethod method;
volatile public bool processed;
public Exception ex = null;
};
////////////////////////////////////////////
@@ -113,6 +114,14 @@ namespace renderdocui.Code
public float LoadProgress;
[ThreadStatic]
private bool CatchExceptions = false;
public void SetExceptionCatching(bool catching)
{
CatchExceptions = catching;
}
public void BeginInvoke(InvokeMethod m)
{
InvokeHandle cmd = new InvokeHandle(m);
@@ -127,6 +136,9 @@ namespace renderdocui.Code
PushInvoke(cmd);
while (!cmd.processed) ;
if (cmd.ex != null)
throw cmd.ex;
}
private void PushInvoke(InvokeHandle cmd)
@@ -204,7 +216,23 @@ namespace renderdocui.Code
foreach (var cmd in queue)
{
if (cmd.method != null)
cmd.method(renderer);
{
if (CatchExceptions)
{
try
{
cmd.method(renderer);
}
catch (Exception ex)
{
cmd.ex = ex;
}
}
else
{
cmd.method(renderer);
}
}
cmd.processed = true;
}