winterhell's picture

Project crashes on startup on OS X, works fine on Linux and Windows

I used MonoKickstart to launch the project. OpenTK 1.1, with and without SDL2. This is what I get in a virtual machine(mountain lion) and on a macbook:

Stacktrace:
 
  at (wrapper managed-to-native) OpenTK.Platform.MacOS.Carbon.CG.DisplayBounds (intptr) <0xffffffff>
  at OpenTK.Platform.MacOS.QuartzDisplayDeviceDriver..ctor () <0x00447>
  at OpenTK.Platform.MacOS.MacOSFactory.CreateDisplayDeviceDriver () <0x0002f>
  at OpenTK.DisplayDevice..cctor () <0x0004a>
  at (wrapper runtime-invoke) object.runtime_invoke_void (object,intptr,intptr,intptr) <0xffffffff>
  at OpenTK.GameWindow..ctor (int,int,OpenTK.Graphics.GraphicsMode,string) <0x00028>
  at IORE.Game1..ctor () <0x00061>
  at IORE.Game1.Main () <0x0004b>
  at (wrapper runtime-invoke) object.runtime_invoke_void (object,intptr,intptr,intptr) <0xffffffff>
 
Native stacktrace:
 
	0   libmono-2.0.1.dylib                 0x0000000102e2ba04 mono_handle_native_sigsegv + 260
	1   libmono-2.0.1.dylib                 0x0000000102dabf96 mono_sigsegv_signal_handler + 198
	2   libsystem_platform.dylib            0x00007fff8888f5aa _sigtramp + 26
....
 
./Kick: line 23: 35347 Abort trap: 6           ./kick.bin.osx $@

When I try to run it on the virtual machine directly from the terminal "mono myProject.exe" I get a different error that seems unrelated to OpenTK(SortedDictionary).

What could be the cause of this?


Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
the Fiddler's picture

Hm, OpenTK.dll does not contain any references to SortedDictionary. It does contain a couple of references to SortedList, which can (and should) be removed.

Which version of Mono are you using in each case?

Edit: these two crashes appear to be unrelated. I can reproduce the crash in the first case, but not in the second.

Are you compiling a custom build of OpenTK, or are you using the precompiled dll from sourceforge?

winterhell's picture

in the virtual machine I installed 3.4 MDK on top of the 2.1 Runtime I had.
On the macbook they told me there is probably no mono installed.

the Fiddler's picture

Nice, I hadn't realized Mono 3.4 is out. I am still on 3.2.6, which works as expected.

I will try to install 3.4 and see if I can reproduce the crash.

the Fiddler's picture

The crash in CGDisplayBounds was caused by a mismatch of the signature with the x86 Mac ABI which, for some strange reason, only exploded when running through monokickstart. This is now fixed in https://github.com/opentk/opentk/pull/96

Execution now halts at a different place:

[ERROR] FATAL UNHANDLED EXCEPTION: System.TypeInitializationException: An exception was thrown by the type initializer for OpenTK.Platform.MacOS.CarbonGLNative ---> System.TypeInitializationException: An exception was thrown by the type initializer for OpenTK.Platform.MacOS.Carbon.Application ---> System.EntryPointNotFoundException: NewEventHandlerUPP
  at (wrapper managed-to-native) OpenTK.Platform.MacOS.Carbon.API:NewEventHandlerUPP (OpenTK.Platform.MacOS.Carbon.MacOSEventHandler)
  at OpenTK.Platform.MacOS.Carbon.Application.ConnectEvents () [0x00000] in <filename unknown>:0 
  at OpenTK.Platform.MacOS.Carbon.Application.Initialize () [0x00000] in <filename unknown>:0 
  at OpenTK.Platform.MacOS.Carbon.Application..cctor () [0x00000] in <filename unknown>:0 
  --- End of inner exception stack trace ---
  at OpenTK.Platform.MacOS.CarbonGLNative..cctor () [0x00000] in <filename unknown>:0 
  --- End of inner exception stack trace ---
  at OpenTK.Platform.MacOS.MacOSFactory.CreateNativeWindow (Int32 x, Int32 y, Int32 width, Int32 height, System.String title, OpenTK.Graphics.GraphicsMode mode, GameWindowFlags options, OpenTK.DisplayDevice device) [0x00000] in <filename unknown>:0 
  at OpenTK.NativeWindow..ctor (Int32 x, Int32 y, Int32 width, Int32 height, System.String title, GameWindowFlags options, OpenTK.Graphics.GraphicsMode mode, OpenTK.DisplayDevice device) [0x00000] in <filename unknown>:0 
  at OpenTK.NativeWindow..ctor (Int32 width, Int32 height, System.String title, GameWindowFlags options, OpenTK.Graphics.GraphicsMode mode, OpenTK.DisplayDevice device) [0x00000] in <filename unknown>:0 
  at OpenTK.GameWindow..ctor (Int32 width, Int32 height, OpenTK.Graphics.GraphicsMode mode, System.String title, GameWindowFlags options, OpenTK.DisplayDevice device, Int32 major, Int32 minor, GraphicsContextFlags flags, IGraphicsContext sharedContext) [0x00000] in <filename unknown>:0 
  at OpenTK.GameWindow..ctor (Int32 width, Int32 height, OpenTK.Graphics.GraphicsMode mode, System.String title, GameWindowFlags options, OpenTK.DisplayDevice device, Int32 major, Int32 minor, GraphicsContextFlags flags) [0x00000] in <filename unknown>:0 
  at OpenTK.GameWindow..ctor (Int32 width, Int32 height, OpenTK.Graphics.GraphicsMode mode, System.String title, GameWindowFlags options, OpenTK.DisplayDevice device) [0x00000] in <filename unknown>:0 
  at OpenTK.GameWindow..ctor (Int32 width, Int32 height, OpenTK.Graphics.GraphicsMode mode, System.String title) [0x00000] in <filename unknown>:0 
  at IORE.Game1..ctor () [0x00000] in <filename unknown>:0 
  at IORE.Game1.Main () [0x00000] in <filename unknown>:0

Edit: this does not appear to be an issue with OpenTK. Enabling MONO_LOG_LEVEL=debug gives the following output:

MONO_LOG_LEVEL=debug sh Kick
[....]
Mono: DllImport attempting to load: '/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon'.
Mono: DllImport loading library: '/Users/[retracted]/dev/projects/tests/TestMFC001f/lib/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon'.
Mono: Searching for 'NewEventHandlerUPP'.
Mono: Probing 'NewEventHandlerUPP'.
Mono: Probing 'NewEventHandlerUPP'.
Mono: Probing 'NewEventHandlerUPPA'.
Mono: Probing 'NewEventHandlerUPPA'.

When running mono directly:

MONO_LOG_LEVEL=debug mono kick.exe
[...]
Mono: DllImport searching in: '/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon' ('/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon').
Mono: Searching for 'NewEventHandlerUPP'.
Mono: Probing 'NewEventHandlerUPP'.
Mono: Found as 'NewEventHandlerUPP'.

This issue appears to be related to mono-kickstart, so you might have better luck reporting it there.

the Fiddler's picture

It appears that MonoKickstart is running the application in x64 mode. This is not officially supported by the Mono runtime on Mac OS X, nor by Carbon.framework. (Funnily enough, it appears that x64 symbols exist and can be used there, but ABI incompatibilities are throwing us off.)

If you copy the x64 version of libSDL2.dylib from opentk/Dependencies/x64, you can actually launch the application correctly. However, you will then get a failure for a missing libgdiplus.dll, because Mono does not ship a x64 version of this library on Mac OS X.

Edit: it is possible to remove the 64bit runtime with:

mv kick.bin.osx kick.bin.osx.fat
lipo kick.bin.osx.fat -remove x86_64 -output kick.bin.osx

Edit 2: this avoids the crashes from the original post, but still fails with a DllNotFoundException on gdiplus.dll.

the Fiddler's picture

Success!

I can run your test application unmodified, using the following steps:

1. Remove the 64bit runtime with:

mv kick.bin.osx kick.bin.osx.fat
lipo kick.bin.osx.fat -remove x86_64 -output kick.bin.osx

2. Copy libgdiplus from an existing mono installation:

cp /Library/Frameworks/Mono.framework/Libraries/libgdiplus.0.dylib osx/libgdiplus.dylib

3. (optional) Use SDL2 for retina support:

cp ~/opentk/Dependencies/x86/libSDL2.dylib osx/libSDL2.dylib

4. Run with:

sh Kick

In theory you could also compile a 64bit version of libgdiplus and SDL2, and run your application in 64bit mode. This is untested but should work.

winterhell's picture

Great, it worked!

I'm ok with using 32-bit .Net 2.0.
The SortedDictionary error turned out to be due to the program trying to read files that were from the place I was calling Mono from, and not where the executable was.

Do you have any guesses why the shader is not working? The GLSL is 1.2 and works on Windows
Basically I have

 
           GL.EnableVertexAttribArray(0);
           GL.EnableVertexAttribArray(1);
           GL.UseProgram( 
           GL.Uniform1(
           GL.BindTexture(
           GL.BindBuffer(BufferTarget.ArrayBuffer, texcoordVboHandle);
           GL.VertexAttribPointer(1, 2, VertexAttribPointerType.Float, false, Vector2.SizeInBytes, 0);
          GL.BindBuffer(BufferTarget.ArrayBuffer, positionVboHandle);
          GL.VertexAttribPointer(0, 3, VertexAttribPointerType.Float, false, OpenTK.Vector3.SizeInBytes, 0);
          GL.DrawArrays(PrimitiveType.Quads, 0, 4);
the Fiddler's picture

Use GL.GetShaderInfoLog() for each shader and GL.GetProgramInfoLog() for the program to retrieve information about the errors.

From a quick look, replace "in" with "varying" and remove the "precision" qualifier. These features are not supported in #version 120.

winterhell's picture

I'm using varying instead of "out", which gave errors when I was compiling on windows. Will check the rest.

Edit: Turns out Apple's OpenGL was more conservative and required "attribute" instead of "in".