luca-piccioni / OpenGL.Net

Modern OpenGL bindings for C#.
MIT License
570 stars 109 forks source link

Core dump when running under Mono #65

Open Xyene opened 6 years ago

Xyene commented 6 years ago

Hi,

I'm running into some initialization issues while testing an app under a certain device, with the app exiting violently. I implement a backup software renderer in case OpenGL.Net is unable to initialize, but am unable to use it in this case as OpenGL.Net crashes immediately, during the test to see if it can render 😄

The crash itself appears to be originating in native code at https://github.com/luca-piccioni/OpenGL.Net/blob/c7f6f2f233784497b5e2f787cf0ca2acbabddb17/OpenGL.Net/Egl.cs#L122

System Info

I'm running OpenGL.Net and OpenGL.Net.WinForms, both v0.6.0.

$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 16.04.2 LTS
Release:    16.04
Codename:   xenial
$ uname -a
Linux lycan 4.4.0-43-Microsoft #1-Microsoft Wed Dec 31 14:42:53 PST 2014 x86_64 x86_64 x86_64 GNU/Linux
$ apt list --installed | grep ^mono*
mono-4.0-gac/xenial,now 4.2.1.102+dfsg2-7ubuntu4 all [installed,automatic]
mono-4.0-service/xenial,now 4.2.1.102+dfsg2-7ubuntu4 all [installed,automatic]
mono-complete/xenial,now 4.2.1.102+dfsg2-7ubuntu4 amd64 [installed]
mono-csharp-shell/xenial,now 4.2.1.102+dfsg2-7ubuntu4 all [installed,automatic]
mono-devel/xenial,now 4.2.1.102+dfsg2-7ubuntu4 all [installed,automatic]
mono-gac/xenial,now 4.2.1.102+dfsg2-7ubuntu4 all [installed,automatic]
mono-jay/xenial,now 4.2.1.102+dfsg2-7ubuntu4 amd64 [installed,automatic]
mono-mcs/xenial,now 4.2.1.102+dfsg2-7ubuntu4 all [installed,automatic]
mono-runtime/xenial,now 4.2.1.102+dfsg2-7ubuntu4 amd64 [installed]
mono-runtime-common/xenial,now 4.2.1.102+dfsg2-7ubuntu4 amd64 [installed,automatic]
mono-runtime-sgen/xenial,now 4.2.1.102+dfsg2-7ubuntu4 amd64 [installed,automatic]
mono-utils/xenial,now 4.2.1.102+dfsg2-7ubuntu4 amd64 [installed,automatic]
mono-xbuild/xenial,now 4.2.1.102+dfsg2-7ubuntu4 all [installed,automatic]
monodoc-base/xenial,now 4.2.1.102+dfsg2-7ubuntu4 all [installed,automatic]
monodoc-browser/xenial,now 4.2-1 all [installed,automatic]
monodoc-manual/xenial,now 4.2.1.102+dfsg2-7ubuntu4 all [installed,automatic]

glxinfo output: https://gist.github.com/Xyene/e12ae0871dd6d329dc5b7e5c9654d36a

The crashes seem to randomly cycle through 3 versions, listed below.

Crash 1: https://gist.github.com/Xyene/39aeb1264e377d2bdb983ca866bd591d

Crash 2:

mono: malloc.c:3722: _int_malloc: Assertion `(unsigned long) (size) >= (unsigned long) (nb)' failed.
Stacktrace:

  at <unknown> <0xffffffff>

Crash 3 (not a fatal error): image

This error seems to be equivalent to the error generated when running with OPENGL_NET_EGL_STATIC_INIT=NO.

luca-piccioni commented 6 years ago

The crash n. 1 seem caused directly by the EGL implementer, in eglInitialize. The Egl static constructor is invoking Egl.Initialize, passing the display handle as argument: I don't how this can interfere with un-managed EGL implementation.

The crash n. 2 has not enough context. When the assertion is caught? How the Mono/C run-time is supposed to run assertions? From the assertion text, I can imply that insufficient memory has been allocated (by Mono run-time, I suppose).

The crash n. 3 seems related to #66. Disabling/skip EGL initialization, somehow try to run on GLX, which is not initialized (indeed no function pointers).

To solve n. 2, I suggest to upgrade/change mono run-time.

A good way to find the culprit for n.1 is to build a working native example. Then, check if you're application is executing the same EGL/GL commands. If it does, and it doesn't work as expected, the problem can be a P/Invoke bug, or just something else: any library dependency required to be loaded, just like this?

luca-piccioni commented 6 years ago

Recently I'm running on the last mono implementation, and I get similar behavior. I think this is related with #77.

I suspect that is a memory corruption issue due a wrong P/invoke management. Moreover I think there are in EGL and GLX APIs; strange, because previous mono implementation (on Linux and on RPi) this issue were not present.