Fidchells_eye's picture

Error: Failed to swap buffers for context 196608 Current. Error 6.

Can someone help me with this problem.

I am trying to thread the GL Processing and rendering in a thread, but get this error.

Do I need to make some delegate, invoke, or event method to handle this?

Code
**************************************

private void cmdRT_Test_Click(object sender, EventArgs e) //<----- Do a thread test in here for speed testing propose?
{
HT_RT_Test_Start = new ThreadStart(HT_Test.HT_Test_File);
HT_RT_Test = new Thread(HT_RT_Test_Start);
HT_RT_Test.Start();

string name = vidgrab.StoragePath + "\\TempTest.bmp";
uint i = 0;
Stopwatch watch = new Stopwatch();
watch.Reset();
watch.Start();
do
{
vidgrab.CaptureFrameSyncTo(VidGrab.TFrameCaptureDest.fc_BmpFile, "TempTest");
HT_Test.Filename = name;
while(!HT_Test.Next)
{
Application.DoEvents();
}

i++;
} while (i < 30);
watch.Stop();
HT_Test.TermainateMe = true;
HT_RT_Test.Join();
MessageBox.Show(watch.ElapsedMilliseconds.ToString());*/
}

********************************

public class ThreadTest
{
#region Data
protected ScopeBase sBase;
protected bool termainateMe = false;
protected bool next = false;
protected string file = string.Empty;
#endregion
public ThreadTest(ref OpenTK.GLControl GL_Display, ScopeBase.ScopeMode mode)
{
if (mode == ScopeBase.ScopeMode.WFM)
{
sBase = new Scope_WFM(ref GL_Display);
}
else if (mode == ScopeBase.ScopeMode.VTR)
{
sBase = new Scope_VTR(ref GL_Display);
}
else if (mode == ScopeBase.ScopeMode.RGB)
{
sBase = new Scope_RGB(ref GL_Display);
}
else if (mode == ScopeBase.ScopeMode.YUV)
{
sBase = new Scope_YUV(ref GL_Display);
}
else if (mode == ScopeBase.ScopeMode.HST)
{
sBase = new Scope_HST(ref GL_Display);
}
else
{

}
//gl = GL_Display;
}

public void HT_Test_File() //requires that the scope is configured before use
{
this.TermainateMe = false;
this.Next = false;
//check if things are OK
if (!scope.IsOKtoRun())
{
return;
}

do
{
this.Next = false;
do
{
Application.DoEvents();
}
while (this.file == string.Empty && this.TermainateMe == false);

if (this.TermainateMe == true)
{
break;
}
else
{
try
{
scope.Render(ref file);
this.Next = true;
this.Filename = string.Empty;
}
catch(Exception ex)
{
MessageBox.Show(ex.Message + "\n Thread SHUTDOWN.");
return;
}
}
}
while(this.TermainateMe==false);

}

#region GettersNSetters
public ScopeBase scope
{
get
{
return sBase;
}

set
{
sBase = value;
}
}
public string Filename
{
get
{
return this.file;
}

set
{
this.file = value;
}
}
public bool Next
{
get
{
return this.next;
}

set
{
this.next = value;
}
}
public bool TermainateMe
{
get
{
return this.termainateMe;
}

set
{
this.termainateMe = value;
}
}
#endregion
}