{"action":"created","issue":{"url":"https://api.github.com/repos/luca-piccioni/OpenGL.Net/issues/77","repository_url":"https://api.github.com/repos/luca-piccioni/OpenGL.Net","labels_url":"https://api.github.com/repos/luca-piccioni/OpenGL.Net/issues/77/labels{/name}","comments_url":"https://api.github.com/repos/luca-piccioni/OpenGL.Net/issues/77/comments","events_url":"https://api.github.com/repos/luca-piccioni/OpenGL.Net/issues/77/events","html_url":"https://github.com/luca-piccioni/OpenGL.Net/issues/77","id":270889767,"number":77,"title":"Delegates.pglXCreateContextAttribsARB is null on Linux","user":{"login":"manuelxmarquez","id":30425852,"avatar_url":"https://avatars0.githubusercontent.com/u/30425852?v=4","gravatar_id":"","url":"https://api.github.com/users/manuelxmarquez","html_url":"https://github.com/manuelxmarquez","followers_url":"https://api.github.com/users/manuelxmarquez/followers","following_url":"https://api.github.com/users/manuelxmarquez/following{/other_user}","gists_url":"https://api.github.com/users/manuelxmarquez/gists{/gist_id}","starred_url":"https://api.github.com/users/manuelxmarquez/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/manuelxmarquez/subscriptions","organizations_url":"https://api.github.com/users/manuelxmarquez/orgs","repos_url":"https://api.github.com/users/manuelxmarquez/repos","events_url":"https://api.github.com/users/manuelxmarquez/events{/privacy}","received_events_url":"https://api.github.com/users/manuelxmarquez/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":2,"created_at":"2017-11-03T06:40:36Z","updated_at":"2017-11-04T16:46:40Z","closed_at":null,"author_association":"NONE","body":"I am getting the following exception on Linux (Ubuntu and ZorinOS VMs).\r\n\r\nSystem.NullReferenceException: Object reference not set to an instance of an object\r\n  at OpenGL.Glx.CreateContextAttribsARB (System.IntPtr dpy, System.IntPtr config, System.IntPtr share_context, System.Boolean direct, System.Int32[] attrib_list) [0x00018] in <e12789fbcdef4c709d7cf91735f649bd>:0 \r\n  at OpenGL.DeviceContextGLX.CreateContextAttrib (System.IntPtr sharedContext, System.Int32[] attribsList, OpenGL.KhronosVersion api) [0x00283] in <e12789fbcdef4c709d7cf91735f649bd>:0 \r\n  at OpenGL.DeviceContextGLX.CreateContextAttrib (System.IntPtr sharedContext, System.Int32[] attribsList) [0x00010] in <e12789fbcdef4c709d7cf91735f649bd>:0 \r\n  at WindowTester.Program.Main (System.String[] args) [0x00314] in <09e86c9ac2f3497a919935f4eb8eae49>:0 \r\nSegmentation fault (core dumped)\r\n\r\nI was able to trace it back to the following delegate being null, Delegates.pglXCreateContextAttribsARB, when calling DeviceContext.CreateContextAttrib.\r\n\r\nIt was actually difficult to trace it since I'm new to OpenGL and Linux. It appears Debug.Assert does not do anything on mono and it's just ignored. Maybe throwing an exception instead is better for compatibility? The are some fixes posted online but the only one that worked for me was attaching a listener to the console.\r\n\r\nI tried different package versions and found that 0.5.2 worked but 0.6.0 did not, if that helps narrow it down.\r\n\r\nHowever, even in that version it only works sometimes. Randomly it crashes with\r\n*** Error in `mono': free(): invalid pointer\r\n\r\nFull dump is attached since it is quite long.\r\n[CrashDump.txt](https://github.com/luca-piccioni/OpenGL.Net/files/1440209/CrashDump.txt)\r\n\r\nI spent a day trying to get this to work but I have no idea how to debug as I'm not a Linux or OpenGL user (coming form Windows Direct3D) but wanted to at least post my findings. I think I will have to use OpenTK for it's stability but I really liked the OpenGL.NET library."},"comment":{"url":"https://api.github.com/repos/luca-piccioni/OpenGL.Net/issues/comments/341911598","html_url":"https://github.com/luca-piccioni/OpenGL.Net/issues/77#issuecomment-341911598","issue_url":"https://api.github.com/repos/luca-piccioni/OpenGL.Net/issues/77","id":341911598,"user":{"login":"manuelxmarquez","id":30425852,"avatar_url":"https://avatars0.githubusercontent.com/u/30425852?v=4","gravatar_id":"","url":"https://api.github.com/users/manuelxmarquez","html_url":"https://github.com/manuelxmarquez","followers_url":"https://api.github.com/users/manuelxmarquez/followers","following_url":"https://api.github.com/users/manuelxmarquez/following{/other_user}","gists_url":"https://api.github.com/users/manuelxmarquez/gists{/gist_id}","starred_url":"https://api.github.com/users/manuelxmarquez/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/manuelxmarquez/subscriptions","organizations_url":"https://api.github.com/users/manuelxmarquez/orgs","repos_url":"https://api.github.com/users/manuelxmarquez/repos","events_url":"https://api.github.com/users/manuelxmarquez/events{/privacy}","received_events_url":"https://api.github.com/users/manuelxmarquez/received_events","type":"User","site_admin":false},"created_at":"2017-11-04T16:46:40Z","updated_at":"2017-11-04T16:46:40Z","author_association":"NONE","body":"I was able to get this example working. Ignore the fact that it's SharpGL (and a bit messy), I don't think SharpGL has Glx, it's just something I hacked together since I was mixing languages. I copied the relevant PInvokes below.\r\n\r\n```\r\n                Dim display = SharpGL.Linux.Glx.XOpenDisplay(IntPtr.Zero)\r\n\r\n                Console.WriteLine($\"display: {display}\")\r\n\r\n                Dim screen = SharpGL.Linux.Glx.XDefaultScreen(display)\r\n\r\n                Console.WriteLine($\"screen: {screen}\")\r\n\r\n                Dim attributes = {4,' GLX_RGBA\r\n                    12,' GLX_DEPTH_SIZE\r\n                    24,' 24\r\n                    5,' GLX_DOUBLEBUFFER\r\n                    0' None\r\n                    }\r\n\r\n                Dim vis = SharpGL.Linux.Glx.ChooseVisual(display, screen, attributes)\r\n\r\n                Console.WriteLine($\"vis: {vis}\")\r\n\r\n                Dim hrDC = SharpGL.Linux.Glx.CreateContext(display, vis, IntPtr.Zero, True)\r\n\r\n                Console.WriteLine($\"hrDC: {hrDC}\")\r\n\r\n                Dim extensionString = SharpGL.Linux.Glx.QueryExtensionsString(display, screen)\r\n\r\n                Console.WriteLine($\"extensionString: {extensionString}\")\r\n\r\n\r\n                SharpGL.Linux.Glx.MakeCurrent(display, window.Handle, hrDC)\r\n\r\n                Console.WriteLine(\"MakeCurrent\")\r\n\r\n\r\n\r\n                Dim glClearColorPtr = SharpGL.Linux.Glx.GetProcAddress(\"glClearColor\")\r\n\r\n                Console.WriteLine($\"glClearColor: {glClearColorPtr}\")\r\n\r\n                Dim glClearColorFun = CType(Marshal.GetDelegateForFunctionPointer(glClearColorPtr, GetType(glClearColorDelegate)), glClearColorDelegate)\r\n\r\n\r\n\r\n                'SharpGL.Linux.Glx.ClearColor(1, 0, 0, 1)\r\n                glClearColorFun(1, 0, 0, 1)\r\n                SharpGL.Linux.Glx.Clear(SharpGL.Enumerations.AttributeMask.ColorBuffer Or SharpGL.Enumerations.AttributeMask.DepthBuffer)\r\n\r\n                SharpGL.Linux.Glx.SwapBuffers(display, window.Handle)\r\n\r\n                'SharpGL.Linux.Glx.ClearColor(0, 1, 0, 1)\r\n                glClearColorFun(0, 1, 0, 1)\r\n                SharpGL.Linux.Glx.Clear(SharpGL.Enumerations.AttributeMask.ColorBuffer Or SharpGL.Enumerations.AttributeMask.DepthBuffer)\r\n```\r\nAnd the relevant PInvokes\r\n\r\n```\r\n        [DllImport(\"libX11\", EntryPoint = \"XOpenDisplay\")]\r\n        public extern static IntPtr XOpenDisplay(IntPtr display);\r\n\r\n        [DllImport(\"libX11\", EntryPoint = \"XDefaultScreen\")]\r\n        public extern static int XDefaultScreen(IntPtr display);\r\n\r\n        [DllImport(Library, EntryPoint = \"glXChooseVisual\")]\r\n        public extern static IntPtr ChooseVisual(IntPtr dpy, int screen, IntPtr attriblist);\r\n\r\n        [DllImport(Library, EntryPoint = \"glXChooseVisual\")]\r\n        public extern static IntPtr ChooseVisual(IntPtr dpy, int screen, ref int attriblist);\r\n\r\n        public static IntPtr ChooseVisual(IntPtr dpy, int screen, int[] attriblist)\r\n        {\r\n            unsafe\r\n            {\r\n                fixed (int* attriblist_ptr = attriblist)\r\n                {\r\n                    return ChooseVisual(dpy, screen, (IntPtr)attriblist_ptr);\r\n                }\r\n            }\r\n        }\r\n\r\n        [DllImport(Library, EntryPoint = \"glXCreateContext\")]\r\n        public static extern IntPtr CreateContext(IntPtr dpy, IntPtr vis, IntPtr shareList, bool direct);\r\n\r\n        [DllImport(Library, EntryPoint = \"glXQueryExtensionsString\")]\r\n        private static extern IntPtr QueryExtensionsStringInternal(IntPtr dpy, int screen);\r\n\r\n        public static string QueryExtensionsString(IntPtr dpy, int screen)\r\n        {\r\n            return Marshal.PtrToStringAnsi(QueryExtensionsStringInternal(dpy, screen));\r\n        }\r\n\r\n        [DllImport(Library, EntryPoint = \"glXMakeCurrent\")]\r\n        public static extern bool MakeCurrent(IntPtr display, IntPtr drawable, IntPtr context);\r\n\r\n        [DllImport(Library, EntryPoint = \"glXGetProcAddress\")]\r\n        public static extern IntPtr GetProcAddress([MarshalAs(UnmanagedType.LPTStr)] string procName);\r\n\r\n        [DllImport(Library, EntryPoint = \"glXGetProcAddress\")]\r\n        public static extern IntPtr GetProcAddress(IntPtr procName);\r\n```\r\n\r\nI hope that gives you some idea of what works and what the problem might be. Let me know if you would like me to try something out on Linux."}}
{"actor":{"display_login":"manuelxmarquez"}}