[fpc-devel] Cannot trap divide by zero in xmm register

Anthony Walter sysrpl at gmail.com
Tue Jun 20 14:57:15 CEST 2017

I am having a problem with unrecoverable errors in external code,
presumably generated by the video driver, crashing my programs. I cannot
trap these errors with try..except blocks. Here is a capture of the
assembler window with ** marking the line where the error occurs.

  00007FFFEA79016F 4898                     cltq
**00007FFFEA790171 f20f5e44c430             divsd  0x30(%rsp,%rax,8),%xmm0
  00007FFFEA790177 f20f118424f8000000       movsd  %xmm0,0xf8(%rsp)
  00007FFFEA790180 f20f118424f0000000       movsd  %xmm0,0xf0(%rsp)
  00007FFFEA790189 f20f118424e8000000       movsd  %xmm0,0xe8(%rsp)

In pascal code I am attempting to link a glsl program (part of OpenGL) when
the uncatchable and unrecoverable error occurs.

*function* TShaderProgram.Link: Boolean;
  I: GLint;
  S: string;
  *if* Flinked *then*
  *if* FAttachCount < 2 *then*
  FLinked := True;
  *// Sometimes the uncatchable error happens here*
  glGetProgramiv(FHandle, GL_LINK_STATUS, @I);
  FValid := I = GL_TRUE;
  *if* *not* FValid *then*
    FErrorObject := Self;
    glGetProgramiv(FHandle, GL_INFO_LOG_LENGTH, @I);
    *if* I > 0 *then*
      SetLength(S, I);
      glGetProgramInfoLog(FHandle, I, @I, PChar(S));
      S := 'Unknown error';
    FErrorString := S;

In this code I am attempting to link user defined glsl vertex and fragment
shaders to generate a valid glsl program object. Sometimes either the
vertex or fragment shader contains bad code, but it shouldn't bring down my
entire pascal application. I've written and used these same shaders in c#
using mono and I've never had them crash my mono applications. Is there
some setting in fpc or in lazarus to handle these types of errors in the
XMM registers gracefully?

To give you an idea of what I am doing, here is a screen recording of made
earlier of these same shader programs running without crashing my
application when using mono.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-devel/attachments/20170620/cce6e3ae/attachment.html>

More information about the fpc-devel mailing list