Recent

Author Topic: [Solved] Cocoa widgetset throws "Failed to create RenderingContext" on MacOS  (Read 828 times)

FangQ

  • Full Member
  • ***
  • Posts: 134
As I described in another thread, I am trying to build a GUI application in 64bit in order to run on MacOS-12 or newer.

My app source code can be found here: https://github.com/fangq/mcx/tree/master/mcxstudio

it can be build with

Code: [Select]
lazbuild --ws=carbon --cpu=i386 mcxstudio.lpr
and run on all old MacOS without any issue. It uses GLScene to render 3D objects and 3D volumetric data. However, carbon does not support x86_64, so I tried

Code: [Select]
lazbuild --ws=cocoa --cpu=x86_64 mcxstudio.lpr
the build is fine, but when running it, it always throw an error "Failed to create RenderingContext", see screenshot below. I tried lazarus 2.2.6 and 2.0.12, got the same error. This also happens on both macos 10.x and 12.x. So, it looks like cocoa does not work with OpenGL or GLScene.

I also tried other widgetsets, but all ended with various types of errors, for example:

Code: [Select]
$lazbuild --ws=qt5 --cpu=x86_64 mcxstudio.lpr
...
ld: framework not found Qt5Pas
An error occurred while linking
/Users/fangq/space/git/Project/github/mcx/mcxstudio/mcxstudio.lpr(20,34) Error: (9013) Error while linking

Code: [Select]
$lazbuild --ws=qt --cpu=x86_64 mcxstudio.lpr
...
(3104) Compiling ./glscene/GLLCLViewer.pas
/Users/fangq/space/git/Project/github/mcx/mcxstudio/./glscene/GLLCLViewer.pas(208,11) Error: (2023) User defined: unimplemented QT context
(3104) Compiling ./glscene/GLViewer.pas
/Users/fangq/space/git/Project/github/mcx/mcxstudio/./glscene/GLViewer.pas(44,1) Fatal: (10026) There were 1 errors compiling module, stopping
Fatal: (1018) Compilation aborted

Code: [Select]
$lazbuild --ws=gtk2 --cpu=x86_64 mcxstudio.lpr
...
(3104) Compiling ./glscene/GLWidgetContext.pas
(3104) Compiling ./glscene/GLCarbonContext.pas
/Users/fangq/space/git/Project/github/mcx/mcxstudio/./glscene/GLCarbonContext.pas(26,32) Fatal: (10022) Can't find unit CarbonDef used by GLCarbonContext
Fatal: (1018) Compilation aborted
Error: /usr/local/bin/ppcx64 returned an error exitcode
Error: (lazarus) Compile Project, Mode: Release, Target: debug/mcxstudio: stopped with exit code 1
Error: (lazbuild) failed compiling of project /Users/fangq/space/git/Project/github/mcx/mcxstudio/mcxstudio.lpi


it looks like qt5 is the closest to complete build as it failed only during linking while others failed during compilation.

in your opinion, is this a Cocoa widgetset bug? or is it a GLScene bug? if I want to resolve the "ld: framework not found Qt5Pas" error, what should I do?

thanks
« Last Edit: September 20, 2023, 05:39:13 pm by FangQ »

ChrisR

  • Full Member
  • ***
  • Posts: 247
Re: Cocoa widgetset throws "Failed to create RenderingContext" error on MacOS
« Reply #1 on: September 19, 2023, 09:49:27 pm »
First, make sure you have installed the lazopenglcontext package - you can do this in the Lazarus user interface or using the command line:

lazbuild --build-ide= --add-package lazopenglcontext

Be aware that for 64-bit Macs can support legacy OpenGL up to version 2.1. If you want to use more recent features, you must use the Core specification of OpenGL. OpenGL core is shader only ad forbids many legacy calls. You can find some demos of OpenGL core here:

https://github.com/neurolabusc/OpenGLCoreTutorials

cdbc

  • Hero Member
  • *****
  • Posts: 1646
    • http://www.cdbc.dk
Re: Cocoa widgetset throws "Failed to create RenderingContext" error on MacOS
« Reply #2 on: September 19, 2023, 10:05:30 pm »
Hi
About your missing Qt5 framework, you are missing the "libqt5pas.so" and corresponding "Qt5Pas.pas" files. dbannon has one i his repo: https://github.com/davidbannon/libqt5pas You need to build this or get similar from your mac repo? I think the pascal-bindings are already in your lazarus installation, otherwise you need to look for that aswell.
Then you  should be able to compile your Qt5 version...
Regards Benny
If it ain't broke, don't fix it ;)
PCLinuxOS(rolling release) 64bit -> KDE5 -> FPC 3.2.2 -> Lazarus 2.2.6 up until Jan 2024 from then on it's: KDE5/QT5 -> FPC 3.3.1 -> Lazarus 3.0

zeljko

  • Hero Member
  • *****
  • Posts: 1668
    • http://wiki.lazarus.freepascal.org/User:Zeljan
Re: Cocoa widgetset throws "Failed to create RenderingContext" error on MacOS
« Reply #3 on: September 20, 2023, 10:10:53 am »
Better use qt6 on mac, a lot of bugs is fixed and it works better than qt5.

Seenkao

  • Hero Member
  • *****
  • Posts: 610
    • New ZenGL.
Re: Cocoa widgetset throws "Failed to create RenderingContext" error on MacOS
« Reply #4 on: September 20, 2023, 04:47:36 pm »
Вы должны убедится, что GLScene умеет создавать OpenGLContext на Mac Cocoa. Вполне возможно разработчики не занимались этим.

Здесь, на форумах, есть достаточно примеров для Mac Cocoa где используется OpenGL. Если вас не сильно интересует именно GLScene, то можете посмотреть их.

Google translate:
You should make sure that GLScene can create OpenGLContext on Mac Cocoa. It is quite possible that the developers did not do this.

Here on the forums there are enough examples for Mac Cocoa using OpenGL. If you are not particularly interested in GLScene, you can watch them.
Rus: Стремлюсь к созданию минимальных и достаточно быстрых приложений.

Eng: I strive to create applications that are minimal and reasonably fast.
Working on ZenGL

FangQ

  • Full Member
  • ***
  • Posts: 134
Re: Cocoa widgetset throws "Failed to create RenderingContext" error on MacOS
« Reply #5 on: September 20, 2023, 05:38:38 pm »
First, make sure you have installed the lazopenglcontext package - you can do this in the Lazarus user interface or using the command line:

lazbuild --build-ide= --add-package lazopenglcontext

Be aware that for 64-bit Macs can support legacy OpenGL up to version 2.1. If you want to use more recent features, you must use the Core specification of OpenGL. OpenGL core is shader only ad forbids many legacy calls. You can find some demos of OpenGL core here:

https://github.com/neurolabusc/OpenGLCoreTutorials

it is so great seeing you here Chris! thanks a lot for sharing your tutorial repo.

After installing the lazopenglcontext package, I was able to build multiple of your OpenGL tutorial projects, using either Lazarus IDE or lazbuild --ws/--cpu flags. So, it seems the error comes from GLScene side.

I was reading the source code of GLScene_LCL and it seems Carbon is the only widgetset that GLScene supports on the Mac

https://github.com/glscene/GLSceneLCL/blob/54e4cc8225a0888d7e8742fa281222be343c2f2b/Source/GLLCLViewer.pas#L192-L207
https://github.com/glscene/GLSceneLCL/blob/54e4cc8225a0888d7e8742fa281222be343c2f2b/Source/GLWidgetContext.pas#L40-L42

at this point, I will likely have to remove my GL related functions/units to at least let the GUI to build. in the future, seems reimplementing the rendering functions in lazopengl will be the only way to go to continue the mac line.

FangQ

  • Full Member
  • ***
  • Posts: 134
Re: Cocoa widgetset throws "Failed to create RenderingContext" error on MacOS
« Reply #6 on: September 20, 2023, 05:41:31 pm »
Hi
About your missing Qt5 framework, you are missing the "libqt5pas.so" and corresponding "Qt5Pas.pas" files. dbannon has one i his repo: https://github.com/davidbannon/libqt5pas You need to build this or get similar from your mac repo? I think the pascal-bindings are already in your lazarus installation, otherwise you need to look for that aswell.
Then you  should be able to compile your Qt5 version...
Regards Benny

thanks, I now understand that using gtk/qt widgetset will require additional installations to build and run.

from reading the source code, it seems qt is not supported in glscene, so it is going to be a deadend

https://github.com/glscene/GLSceneLCL/blob/54e4cc8225a0888d7e8742fa281222be343c2f2b/Source/GLLCLViewer.pas#L205-L207

for now, I will have to give up glscene on the mac (but still love it for Linux and Windows)

FangQ

  • Full Member
  • ***
  • Posts: 134
I ended up using {$IFDEF}{$ENDIF} to isolate and disabled all GLScene windows from the main GUI, which permits lazbuild to build 64bit app with cocoa

https://github.com/fangq/mcx/commit/1adb6c6a02a3205349e5bb11fabe2e82fd750fe7

I marked this thread as "Solved", but now see a new error, will create a new thread to detail. Thanks again for everyone's help to understand the OpenGL problem.

 

TinyPortal © 2005-2018