bendada's picture

BUG with Opentk.Font

Hello,
I am using opentk for c# project,
I have a problem in opentk.Fonts, I can write text successfully, but sometimes I have an AccessViolationException to draw text on my viewer.
With this instruction:

GL.PushAttrib(OpenTK.OpenGL.Enums.AttribMask.AllAttribBits);
 
TextureFont font = new TextureFont(new Font(_font, FontStyle.Italic));
 
TextHandle handle = null;
 
m_textPrinter.Prepare(_text[i], font, out handle);
 
if (handle != null)
{
    m_textPrinter.Begin();
 
    using (handle)
    {
        GL.Color3(_colorText);
        if (bText)
            GL.Color3(_colorTextSelected);
        GL.Translate(Vertex_Initiale.X + _imarge, Vertex_Initiale.Y + i * _iTailleTextY + _imarge, Vertex_Initiale.Z);
        m_textPrinter.Draw(handle);
    }
    m_textPrinter.End();
    handle.Dispose()
}

My exception is :

System. AccessViolationException

OpenTK. OpenGL. GL. Imports. CallList(UInt32 list) à OpenTK. OpenGL. GL. CallList(Int32 list) à OpenTK. Fonts. DisplayListTextPrinter. Draw(TextHandle handle) à OpenTK. Fonts. TextPrinter. Draw(TextHandle handle)

Does someone know why this exception happens ?
Thanks.
Billel

[mod edit: code tags]

AttachmentSize
WindowsApplication1.rar511.17 KB

Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
the Fiddler's picture

Does the following code crash?

TextureFont font = new TextureFont(new Font(_font, FontStyle.Italic));  // Don't do this every frame! Cache the result instead.
GL.PushAttrib(OpenTK.OpenGL.Enums.AttribMask.AllAttribBits);
 
m_textPrinter.Begin();
 
GL.Color3(_colorText);
if (bText)
    GL.Color3(_colorTextSelected);
GL.Translate(Vertex_Initiale.X + _imarge, Vertex_Initiale.Y + i * _iTailleTextY + _imarge, Vertex_Initiale.Z);
m_textPrinter.Draw(_text[i], font);
 
m_textPrinter.End();

If yes, can you please create an empty project which contains only the text printing routine you wrote? Does this project still crash? This will help narrow down the problem domain.

Edit: Also, which version of OpenTK you are using?

Edit 2: Now that I think of, disposing the handle might cause a crash if the driver renders the (internal) display list asynchronously. Does the crash disappear if you place a GL.Finish() just before the handle.Dispose() call?

bendada's picture

Hello;
Here is a trial project
It is possible that the problem is caused by the type of font used?
I've read that opengl are a problem with the police of Windows, it is correct?