Notice (2018-05-24): bugzilla.xamarin.com is now in
Please join us on
Visual Studio Developer Community and in the
Mono organizations on
GitHub to continue tracking issues. Bugzilla will remain
available for reference in read-only mode. We will continue to work
on open Bugzilla bugs, copy them to the new locations
as needed for follow-up, and add the new items under Related
Our sincere thanks to everyone who has contributed on this bug
tracker over the years. Thanks also for your understanding as we
make these adjustments and improvements for the future.
Please create a new report on
GitHub or Developer Community with
your current version information, steps to reproduce, and relevant error
messages or log files if you are hitting an issue that looks similar to
this resolved bug and you do not yet see a matching new report.
Created attachment 4216 [details]
SSCCE exhibiting the bug
Related StackOverflow question: http://stackoverflow.com/q/17331418/1122135
The way that Mono sets up function parameters is incorrect for by-value structs. Other parameters are shifted over, creating some weird bugs and segfaults.
I packaged the SSCCE I posted on the StackOverflow question as a .tar.gz, this is the output I get on my Linux x86_64 system:
22, (33, 44, 55)
22, (33.000000, 0.000000, 3.179688)
Passing the structs by reference will fix the issue, but will break API compatibility with the library I'm using that exhibits this behavior. Additionally, when there are more parameters, the first int in the struct becomes the next non-struct parameter and the rest of the parameters get shifted down, with the first int showing up as the last parameter.
Additionally, here's some system info that may be of use:
Linux rob-arch 3.9.7-1-ARCH #1 SMP PREEMPT Thu Jun 20 22:45:32 CEST 2013 x86_64 GNU/Linux
CPU op-mode(s): 32-bit, 64-bit
Byte Order: Little Endian
On-line CPU(s) list: 0-7
Thread(s) per core: 2
Core(s) per socket: 4
NUMA node(s): 1
Vendor ID: GenuineIntel
CPU family: 6
Model name: Intel(R) Core(TM) i7-2600K CPU @ 3.40GHz
CPU MHz: 3400.000
L1d cache: 32K
L1i cache: 32K
L2 cache: 256K
L3 cache: 8192K
NUMA node0 CPU(s): 0-7
I can't reproduce this with mono master (on osx-64 though).
I can tell that our company gets exactly the same problem with Ubuntu 12.04.2 LTS x64.
We have a struct containing only float members and pass it by value via P/Invoke to a gcc compiled .so library.
In best case the wrong float values arrive on native side but mostly it causes a crash.
The same code works fine on windows with a dll (VSC compiled) equal if 32Bit or 64Bit!
But on Linux x64 the default struct marshalling (by value) with mono fails somehow.
The only way to resolve it quck is to replace all struct passing per value with passing per reference.
I should add that we are doing a game with Unity Engine 4.2.2 which uses a customized older Mono version. But the same bug applies here as stated by Robert Rouhani. We can confirm what was said the StackOverflow question: http://stackoverflow.com/q/17331418/1122135
What is the output of mono --version ?
"The program 'mono' is currently not installed. You can install it by typing:
sudo apt-get install mono-runtime"
and that is because the Unity game engine ships a customized version of mono as library (libmono.so) contained in every game build.
Should be any Mono 2.x version, it is not stated anywhere, see here: http://forum.unity3d.com/threads/150749-Unity-4-and-Mono-2-6
If this only happens inside unity, you should report it to them. Unity contains a pretty old version of mono and many bugs were fixed in mono since then.
I think we can workaround by using struct references for now. I just wanted to add here that we have the same bug as "Robert Rouhani" encountered.
If i get time i might test it with standalone mono app using the current mono version.
If it occures there again I'll post it here.