Recent

Author Topic: catch TOpenGLContext exceptions  (Read 3913 times)

apeoperaio

  • Sr. Member
  • ****
  • Posts: 273
catch TOpenGLContext exceptions
« on: February 19, 2016, 11:45:40 am »
I developed an application using TOpenGLcontext.
Some users have problems with opengl (especially on linux), missing libraries, FB config missing and so on.

Actually if the system on which my application is running has problems with opengl my app crashes.
e.g.:
"Could not find FB config"
Press OK to ignore and risk data corruption
Press Cancel to kill the program

I would like to catch these exceptions and if Topenglcontext cannot work I would like to disable it and run my app wihout it.

How can I do it?
Thanks.
Andrea

balazsszekely

  • Guest
Re: catch TOpenGLContext exceptions
« Reply #1 on: February 19, 2016, 12:04:09 pm »
You should debug the code and find out which line causing the exception. To handle all exception on application level, switch do release mode, then do this on the main form:
Code: Pascal  [Select][+][-]
  1. //...
  2.  TForm1 = class(TForm)
  3.     procedure FormCreate(Sender: TObject);
  4.   private
  5.     procedure HandleExceptions(Sender: TObject; E: Exception);
  6.     { private declarations }
  7.   public
  8.     { public declarations }
  9.   end;        
  10.  
  11. //...
  12. procedure TForm1.FormCreate(Sender: TObject);
  13. begin
  14.   Application.OnException := @HandleExceptions;
  15. end;
  16.  
  17. procedure TForm1.HandleExceptions(Sender: TObject; E: Exception);
  18. begin
  19.   //handle here --> show something or not, it's up to you
  20.   ShowMessage(E.Message);
  21. end;    
  22.    

apeoperaio

  • Sr. Member
  • ****
  • Posts: 273
Re: catch TOpenGLContext exceptions
« Reply #2 on: February 19, 2016, 12:16:52 pm »
I cannot find where the exception is raised exactly since I am not able to reproduce the problem.

Anyway I just want to not create the TOpenGLContext if OpenGL are not working.
I have a TOpenGLContext on my main form (design time), I would like to catch exceptions related ONLY to opengl and eventually disable in some way the openglcontext and run my application without using TOpenGLContext.
I can create TOpenGLContext at runtime after a test that guarantee me that TOpenGLContext will run.
I want to avoid unexpected crash related to opengl.

Something like

try
  Ok:= TestIFTOpenGLContextCanRun;
except
  messageerror;
end;
if Ok then
  CreateTOpengLContext;
// run my app

 

TinyPortal © 2005-2018