Original Post
Hi, I have a 3d directx c# screensaver that shows a nice object and some realtime monitoring information about servers and visitors. Currently i'm trying to switch the current rendered object with another one. This works fine but i want this process in a background thread. When i'm trying to do this in a background thread while rendering i'm getting an error on the beginscene(); I'm using the following situation. At the line device.BeginScene(); i get the following error. -20005530516 (D3DERR_INVALIDCALL) on Microsoft.DirectX.Direct3D.Device.BeginScene(); Anybody has a clue what's i'm doing wrong. When i don't render anything everything works fine only when i'm trying to render while the thread is running it works for a few seconds and sometimes it works without an error but most of the time it crashes. I use more threading operations (getting xml files from the internet) while rendering that runs fine but they aren't that heavy as this one and doesn't need the device. I use managed Directx Version 1.0.2911.0 Greetings, Dmc
private void LoadNextObject()
{
loadThread = new Thread(new ThreadStart(LoadObjectTask));
loadThread.Start();
}
private void LoadObjectTask()
{
LoadTmpMesh(m_oFramework.Device, MainApp.InstallPath + "Data/" + meshes[new_mesh] + ".obj", MainApp.InstallPath + "Data/" + meshes[new_mesh] + ".shd");
}
private void LoadTmpMesh(Device device, string meshFileName, string resultsFileName)
{
newmeshloading = true;
prtMeshTmp.LoadMesh(device, meshFileName);
prtMeshTmp.LoadCompPrtBufferFromFile(resultsFileName);
prtMeshTmp.ExtractCompressedDataForPrtShader();
prtMeshTmp.LoadEffects(device, device.DeviceCaps);
newmeshloaded = true;
}
In the main render loop i have something like.
public void SceneMainRender(Device device, double appTime, float elapsedTime){
if (newmeshloading )
{
RenderLoadingScreen(device, appTime, elapsedTime);
}
else
{
RenderMesh(device, appTime, elapsedTime);
}
}
private void RenderLoadingScreen(Device device, double appTime, float elapsedTime)
{
bool beginSceneCalled = false;
device.Clear(ClearFlags.ZBuffer | ClearFlags.Target, System.Drawing.Color.FromArgb(0, 200, 200,100), 1.0f, 0);
device.BeginScene(); // <--- Exception on this line after few sec.
beginSceneCalled = true;
// Loadingstuff
if (beginSceneCalled)
device.EndScene();
}