Forum > OpenGL

What's wrong ?

(1/3) > >>

PeterX:
Hi,

I played around with a OpenGL example.

But my derived component does not behave as the code in the MainForm.

What's wrong ?

Handoko:
The issue can be solved simply by adding inherited; at the beginning of your TOpenGLcube.Paint method in myopenglcube.pas.

But I got SIGSEGV exception (see the image below) when closing the program. I found that setting Parent := Panel1; (or := Panel2) in your TForm1.FormCreate will trigger the exception. Unfortunately I haven't found solution for this.

Tested on Lazarus 1.8.4 GTK2 Linux 64-bit.

Thaddy:
Indeed, inherited. The second problem can be solved this way:
Two options
--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---  // manually create the OpenGL object :  OpenGLControl1:= TOpenGLControl.Create(Panel1);  // panel1 becomes owner and parent. This is how it would be with auto create in the designer too.  with OpenGLControl1 do begin    Name     := 'OpenGLControl1';    Align    := alClient;    OnPaint  := @OpenGLControl1Paint;    OnResize := @OpenGLControl1Resize;    AutoResizeViewport:= true;  end;   // manually create the OpenGL object :  OpenGLcube:= TOpenGLcube.Create(Panel2); // panel2 will become owner and parent.  with OpenGLcube do begin    Name     := 'OpenGLcube';    Align    := alClient;    OnPaint  := @Paint;    OnResize := @OpenGLControl1Resize;    AutoResizeViewport:= true;
Second option is to move that code to the subsequent  TPanelX onCreate.
Thus you do not set the Parent, but let the full initialization code run and the parent will be correct automatically.
It can be the case that here the Parent <> Owner if you do it the way you did.

IOW tthere's a logical problem in this code.

PeterX:

--- Quote from: Handoko on March 26, 2019, 04:32:00 am ---The issue can be solved simply by adding inherited; at the beginning of your TOpenGLcube.Paint method in myopenglcube.pas.

But I got SIGSEGV exception (see the image below) when closing the program. I found that setting Parent := Panel1; (or := Panel2) in your TForm1.FormCreate will trigger the exception. Unfortunately I haven't found solution for this.

Tested on Lazarus 1.8.4 GTK2 Linux 64-bit.

--- End quote ---

Thanks, Handoko !

Does not crash on Close under WINDOWS, so must be a Linux issue .. But I did not write

--- Quote ---inherited;

--- End quote ---

because in TCustomOpenGLControl  (unit OpenGLContext)  the paint procedure is virtual:

--- Quote ---    Procedure Paint; virtual; 

--- End quote ---

I thought when virtual, there is nothing to inherit ???

PeterX:
Okay ... even though it's virtual, there is code :

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---procedure TCustomOpenGLControl.Paint;begin  if IsVisible and HandleAllocated then begin    UpdateFrameTimeDiff;    if IsOpenGLRenderAllowed and ([csDestroying]*ComponentState=[]) then begin      if AutoResizeViewport then begin        if not MakeCurrent then exit;        LOpenGLViewport(Handle,0,0,Width,Height);      end;    end;    //LOpenGLClip(Handle);    DoOnPaint;  end;end;          

Navigation

[0] Message Index

[#] Next page

Go to full version