Sign in to follow this  
Cozmoz

PRTEngine problem: ComputeBounce fails

Recommended Posts

Hi everyone, I'm having difficulty getting the PRT engine going. I've reached a point where I want to compute the additional bounces with the ComputeBounce method unfortunately I'm getting a run-time error when I call it. To my mind the code is identical to that found in the examples, but something is obviously wrong and I can't seem to understand why. Here's an excerpt in C#:
            PrtEngine prtEngine = null;
            PrtBuffer prtBuffer = null;
            //used for the additional bounces
            PrtBuffer prtBufferA = null;
            PrtBuffer prtBufferB = null;

            prtEngine = new PrtEngine(mesh, adj, false, null);
//I use a feedback dialog which displays some info 
            if (simSettings.bDisplayFeedback)
            {
                DlgSimRunning dlgSimRunning = new DlgSimRunning();
                dlgSimRunning.Show();
                dlgSimRunning.Update();
                dlgSimRunning.Cursor = Cursors.WaitCursor;

                double dTime = Utilities.FrameworkTimer.GetElapsedTime();

                prtEngine.SetCallback(dlgSimRunning.PercentDone, 0.01f);
                dlgSimRunning.richTextBox1.AppendText("Setting Callback function ..........OK\n");
                dlgSimRunning.Update();

                prtEngine.SetSamplingInfo(simSettings.numberOfRays, false, true, false, 0.0f);
                dlgSimRunning.richTextBox1.AppendText("Setting Sampling Info ..........OK\n");
                dlgSimRunning.Update();

                simSettings.numberOfSamples = prtEngine.NumberVertices;
                prtBuffer = new PrtBuffer(simSettings.numberOfSamples,
                    (simSettings.order * simSettings.order), simSettings.numberOfChannels);
                dlgSimRunning.richTextBox1.AppendText("Creating Buffer ..........OK\n");
                dlgSimRunning.Update();

                prtEngine.ComputeDirectLightingSphericalHarmonics(simSettings.order, prtBuffer);
                dlgSimRunning.richTextBox1.AppendText("Computing SH ..........OK\n");
                dlgSimRunning.Update();

                //additional bounces are calculated here
                if (simSettings.numberOfBounces > 1)
                {
                    prtBufferA = new PrtBuffer(simSettings.numberOfSamples,
                        (simSettings.order * simSettings.order), simSettings.numberOfChannels);
                    prtBufferB = new PrtBuffer(simSettings.numberOfSamples,
                        (simSettings.order * simSettings.order), simSettings.numberOfChannels);
                    prtBufferA.AddBuffer(prtBuffer);
                }
                for (short bounces = 1; bounces < simSettings.numberOfBounces; bounces++)
                {
                    prtEngine.ComputeBounce(prtBufferA, prtBufferB, prtBuffer);//this is where it fails
                    //swap buffers
                    PrtBuffer prtTemp = null;
                    prtTemp = prtBufferA;
                    prtBufferA = prtBufferB;
                    prtBufferB = prtTemp;
                }

Thank you for your time

Share this post


Link to post
Share on other sites
I should have posted this version it's easier to read I think, sorry

PrtEngine prtEngine = null;
PrtBuffer prtBuffer = null;
//used for the additional bounces
PrtBuffer prtBufferA = null;
PrtBuffer prtBufferB = null;

prtEngine = new PrtEngine(mesh, adj, false, null);

Cursor.Current = Cursors.WaitCursor;
prtEngine.SetCallback(simSettings.delegatePercentDone, 0.01f);

prtEngine.SetSamplingInfo(simSettings.numberOfRays, false, true, false, 0.0f);
simSettings.numberOfSamples = prtEngine.NumberVertices;
prtBuffer = new PrtBuffer(simSettings.numberOfSamples,
(simSettings.order * simSettings.order), simSettings.numberOfChannels);
prtEngine.ComputeDirectLightingSphericalHarmonics(simSettings.order, prtBuffer);
if (simSettings.numberOfBounces > 1)
{
prtBufferA = new PrtBuffer(simSettings.numberOfSamples,
(simSettings.order * simSettings.order), simSettings.numberOfChannels);
prtBufferB = new PrtBuffer(simSettings.numberOfSamples,
(simSettings.order * simSettings.order), simSettings.numberOfChannels);
prtBufferA.AddBuffer(prtBuffer);
}
for (short bounces = 1; bounces < simSettings.numberOfBounces; bounces++)
{
prtEngine.ComputeBounce(prtBufferA, prtBufferB, prtBuffer);
//swap buffers
PrtBuffer prtTemp = null;
prtTemp = prtBufferA;
prtBufferA = prtBufferB;
prtBufferB = prtTemp;
}
prtBuffer.Save((@"..\..\" + simSettings.sFileName.Replace(".x", ".prt")));

Cursor.Current = Cursors.Default;


Share this post


Link to post
Share on other sites
Here's an even simpler version, it's based on the calling sequence from the DirectX Documentation for C++. There are supposed to be 4 bounce calculations hence the 4 calls to ComputeBounce at the end.


prtEngine.SetCallback(simSettings.delegatePercentDone, 0.01f);

prtEngine.SetSamplingInfo(simSettings.numberOfRays, false, true, false, 0.0f);
simSettings.numberOfSamples = prtEngine.NumberVertices;
prtBufferA = new PrtBuffer(simSettings.numberOfSamples,
simSettings.order * simSettings.order, simSettings.numberOfChannels);
prtBufferB = new PrtBuffer(simSettings.numberOfSamples,
simSettings.order * simSettings.order, simSettings.numberOfChannels);
prtBufferC = new PrtBuffer(simSettings.numberOfSamples,
simSettings.order * simSettings.order, simSettings.numberOfChannels);

prtEngine.ComputeDirectLightingSphericalHarmonics(simSettings.order, prtBufferA);


prtBufferC.AddBuffer(prtBufferA);
prtEngine.ComputeBounce(prtBufferA, prtBufferB, prtBufferC);
prtEngine.ComputeBounce(prtBufferB, prtBufferA, prtBufferC);
prtEngine.ComputeBounce(prtBufferA, prtBufferB, prtBufferC);
prtEngine.ComputeBounce(prtBufferB, prtBufferA, prtBufferC);



It fails at the first call to ComputeBounce

Here are the exception details

Microsoft.DirectX.Direct3D.Direct3DXException was unhandled
Message="Error in the application."
Source="Microsoft.DirectX.Direct3DX"
ErrorCode=-2005530516
ErrorString="D3DERR_INVALIDCALL"
StackTrace:
at Microsoft.DirectX.Direct3D.PrtEngine.ComputeBounce(PrtBuffer bufferIn, PrtBuffer bufferOut, PrtBuffer dataComputed)
at PRTSimulator.PRTSimFunctions.RunSimulation(SimSettings simSettings) in E:\Visual Studio 2005\Projects\PRTSimulator\PRTSimulator\PRTSimFunctions.cs:line 105
at PRTSimulator.PRTSettingsForm.btnRunSim_Click(Object sender, EventArgs e) in E:\Visual Studio 2005\Projects\PRTSimulator\PRTSimulator\PRTSettingsForm.cs:line 53
at System.Windows.Forms.Control.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ButtonBase.WndProc(Message& m)
at System.Windows.Forms.Button.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.Run(Form mainForm)
at PRTSimulator.Program.Main() in E:\Visual Studio 2005\Projects\PRTSimulator\PRTSimulator\Program.cs:line 18
at System.AppDomain.nExecuteAssembly(Assembly assembly, String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()


Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this