2

I'm trying to embed mono in a c++ executable, and mono crashes on the second evaluator.Run(..) as below. Any idea of what I missed ?

Using mono 3.0.3.

EmbeddedMonoTest.cpp

// EmbeddedMonoTest.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <mono/metadata/debug-helpers.h>
#include <mono/metadata/exception.h>
#include <mono/jit/jit.h>
#include <mono/metadata/assembly.h>
int _tmain(int argc, _TCHAR* argv[])
{
    MonoDomain* domain = mono_jit_init_version ("ClassLibrary1", "v4.0.30319");
    MonoAssembly* assembly  = mono_domain_assembly_open (domain, "ClassLibrary1.dll");  
    mono_assembly_get_image(mono_domain_assembly_open (domain, "Mono.CSharp.dll")); 
    MonoImage* image = mono_assembly_get_image (assembly);
    MonoClass* klass = mono_class_from_name(image, "ClassLibrary1", "Class1");
    MonoMethod* test = mono_class_get_method_from_name(klass, "Test", 0);
    mono_runtime_invoke(test, NULL, NULL, NULL); 
    return 0;
}

Class1.cs

using System;
using System.Reflection;
using Mono.CSharp;

namespace ClassLibrary1
{
    public class Class1
    {
        public static void Test()
        {

            var assembly = Assembly.GetAssembly(typeof(Class1));

            CompilerSettings settings = new CompilerSettings();
            ReportPrinter printer = new ConsoleReportPrinter();
            CompilerContext context = new CompilerContext(settings, printer);
            Evaluator evaluator = new Evaluator(context);
            evaluator.ReferenceAssembly(assembly);
            evaluator.Run("using System; using ClassLibrary1;");
            evaluator.Run("Action<object> action = args => {{ 'x'.ToString(); }}; ");
            evaluator.Run("Action<object> b = args => {{ 'x'.ToString(); }}; ");
        }
    }
}

The error :

Unhandled exception at 0x0274b00d in EmbeddedMonoTest.exe: 0xC0000005: Access violation reading location 0x00000000.

Try something like this:

HTML:

<div class="fadebox">
  <img src="image0.png" />
  <img src="image1.png" />
  <img src="image2.png" />
  <img src="image3.png" />
</div>
<div class="fadebox">
  <img src="image0.png" />
  <img src="image1.png" />
  <img src="image2.png" />
  <img src="image3.png" />
</div>

CSS:

.fadebox {
    position:relative;
}
.fadebox>img {
    position:absolute;
    left:0; top:0;
    opacity:0;
    transition:opacity 1s linear;
    -webkit-transition:opacity 1s linear;
}
.fadebox>img:first-child {
    position:static;
}

JavaScript:

(function() {
    var divs = document.querySelectorAll(".fadebox"), l = divs.length, i;
    for( i=0; i<l; i++) {
        (function(div) {
            var imgs = div.children, l = imgs.length, i = -1,
                step = function() {
                    if(i > -1) imgs[i].style.opacity = 0;
                    i = (i+1)%l;
                    imgs[i].style.opacity = 1;
                };
            step();
            setInterval(step,5000);
        })(divs[i]);
    }
})();

In the above, 1s is the time it takes for the fade to happen, and 5000 is the number of milliseconds the between fades (including the transition, so in this case the image will stay displayed for 4 seconds)

Note that this only works in supporting browsers, like so:

  • IE, Chrome and Firefox should work just fine in their latest versions
  • IE9 works, but don't fade between images
  • IE8 and below don't work due to not supporting opacity
  • IE7 and below don't work due to not supporting querySelectorAll

The last two cases can be fixed by adding a suitable filter style (IE8) and shimming querySelectorAll (IE7 and below)

4

0 回答 0