Search Unity

Awesomium

Discussion in 'Editor & General Support' started by UKdude, Apr 30, 2010.

  1. UKdude

    UKdude

    Joined:
    Apr 30, 2010
    Posts:
    4
    Hi,

    I'm trying to get Awesomium to work in a native windows app, using the .net wrapper class (http://awesomiumdotnet.codeplex.com/releases/view/40589)

    What i've managed so far is to write a seperate command line C# app in visual studio that will call the wrapper class, load my webpage and save it out to the hard disk as .png.

    I need to integrate this functionality into Unity, so I don't need to save the file out and write the image data straight into a texture.

    The problem is unity crashes as soon as I call WebCore core = new WebCore();

    I've copied the wrapper into the plugins folder and the my unity script looks like this:

    Code (csharp):
    1.  
    2. using UnityEngine;
    3. using System;
    4. using System.Collections;
    5. using System.Runtime.InteropServices;
    6. using UnityTexture;
    7. using AwesomiumDotNet;
    8. using System.Threading;
    9. using System.IO;
    10.  
    11. public class SWFScript : MonoBehaviour
    12. {
    13.  
    14.     void Start ()
    15.     {
    16.         WebCore core = new WebCore();
    17.         Debug.Log("Awesomium core started");
    18.     }
    19.  
    20.     void Update ()
    21.     {
    22.     }
    23.    
    24.  
    25. }
    26.  
    I have this editor.log

    Code (csharp):
    1.  
    2. - Finished compile Library/ScriptAssemblies/Assembly - CSharp.dll
    3. Assets/Scripts/SWFScript.cs(15,25): warning CS0219: The variable `core' is assigned but its value is never used
    4.  
    5. (Filename: Assets/Scripts/SWFScript.cs Line: 15)
    6.  
    7. Calculating changed assemblies
    8. End Calculating changed assemblies
    9. Mono: successfully reloaded assembly
    10.        Mono: successfully reloaded assembly
    11. Reload assembly time: 0.474675
    12.  Stacktrace:
    13.  
    14.  at SWFScript.Start () [0x00010] in \Assets\Scripts\SWFScript.cs:17
    15.  at SWFScript.Start () [0x00000] in Assets\Scripts\SWFScript.cs:15
    16.  at (wrapper runtime-invoke) SWFScript.runtime_invoke_void (object,intptr,intptr,intptr) <0xffffffff>
    17. Receiving unhandled NULL exception
    18. unity: Launch crash handler
    19.  
    and this in error.log

    Code (csharp):
    1.  
    2. Unity Editor [version: Unity 2.6.1f3_31223]
    3.  
    4. mono-editor.dll caused an Access Violation (0xc0000005)
    5.   in module mono-editor.dll at 0023:038957dc.
    6.  
    7. Error occurred at 2010-04-30_195750.
    8. C:\Program Files (x86)\Unity\Editor\Unity.exe, run by Chris.
    9. 79% memory in use.
    10. 4095 MB physical memory [858 MB free].
    11. 0 MB paging file [0 MB free].
    12. 0 MB user address space [3037 MB free].
    13. Read from location 00000000 caused an access violation.
    14.  
    Any ideas what's going wrong?
     
  2. Dreamora

    Dreamora

    Joined:
    Apr 5, 2008
    Posts:
    26,601
    Mono 1.2.5 which is in use right now has only .NET 2.0 and has a very flacky and troublesome thread implementation.
    Chances to get it to work has a strong tendency towards 0 I fear and if (if you can kill its multithreading and alike) it will have a disadvantagous impact on your performance.

    Sounds to me like being more an experiment for Unity 3 Pro then.

    I once started on that end too but for me it died with the new license and the massive costs.
     
  3. UKdude

    UKdude

    Joined:
    Apr 30, 2010
    Posts:
    4
    Hmm, that's really annoying. I really want to make the user interface for my game in flash and pipe it into Unity somehow. What about doing something like a seperate app and then somehow sharing the memory between Unity and my C#/C++ app somehow? Anything like that possible?
     
  4. UKdude

    UKdude

    Joined:
    Apr 30, 2010
    Posts:
    4
    BTW, I also tried the .net wrapper for Berkelium (similar to Awesomium) and that seems to have the exact same problem.
     
  5. Dreamora

    Dreamora

    Joined:
    Apr 5, 2008
    Posts:
    26,601
    If you do a standalone build you could use shared system memory.
    But the main problem you will face is the realtime streaming of content into a texture due to the constant uploading etc but you will face that in any case actually
     
  6. solmyr-fr

    solmyr-fr

    Joined:
    Jun 18, 2009
    Posts:
    24
    As I advised you in PM, the best solution is probably to :
    :arrow: do your own C++ class of WebViewListener
    :arrow: create "export C" functions that handle the webcore and a vector of WebViews, compiled it in dll and use it in Unity
     
  7. reissgrant

    reissgrant

    Joined:
    Aug 20, 2009
    Posts:
    726
    Interesting, I am currently looking into integrating Awesomium as well. Like Solmyr, I am planning to call functions from a C++ based DLL although I am still trying to wrap my head around the details.

    Keep in mind too, that there is a solution using webkit, although it is Mac only (at the moment) and it supports Flash/html.
     
  8. niosop2

    niosop2

    Joined:
    Jul 23, 2009
    Posts:
    1,059
    I'd go w/ Berkelium over Awesomium due to licensing issues. Awesomium can be pretty pricey for commercial projects, Berkelium is BSD licensed.

    I figure it would probably be the same amount of work to do either, so I'm going to focus on Berkelium for a bit and see what I can come up with. It would really be a nice GUI layer.
     
  9. Orbcreation

    Orbcreation

    Joined:
    May 4, 2010
    Posts:
    231
    Did anyone make any progress with this topic? Or is there any news about maybe some new usefull features in Unity3?

    In the meantime I am focussing on creating my own simplified html parser that is only capable of displaying texts and images. But real html support would be 100 times better.
     
  10. JeDi

    JeDi

    Joined:
    Jun 16, 2010
    Posts:
    52
    I am also very interested in this functionality.

    If no-one is actively developing this, I will start on it next week, because we need this for a project.
    The project is all about open game development, so I would share all progress and code.

    If someone _is_ actively working on this, I would be happy to cooperate. Or if some code is already available, I could use it as a starting point.

    Note that I have no experience with Unity whatsoever, although other people in our team do. So I will focus on getting the rendering to work first, and then try to get 3D picking to work on the web textures.

    Greetz,
    JeDi
     
  11. ColossalDuck

    ColossalDuck

    Joined:
    Jun 6, 2009
    Posts:
    3,246
    Unity3 will have upgraded mono, with which I believe it will also have upgraded .net. This should fix the problem if I am not mistaken.
     
  12. henriks

    henriks

    Joined:
    Jun 19, 2010
    Posts:
    1
    I have a working berkelium DLL with a very simplified extern "C" interface. However, I still can't get it to run in Unity. It runs fine in a test rig.

    I have written several other DLL's that I use for other purposes.

    It looks like a threading problem, as a previous poster suggested.
     
  13. Dreamora

    Dreamora

    Joined:
    Apr 5, 2008
    Posts:
    26,601
    non native stuff is not related to .NET threading.

    if they don't work your interface with it is incorrect, you don't have pro or you try to use them in webplayer which is a no go (or try to use them on apple which also won't work unless compiled as bundle)


    Question is if the effort is worth it for a $5000 / title tech like awesonium
     
  14. niosop2

    niosop2

    Joined:
    Jul 23, 2009
    Posts:
    1,059
    He did say a test rig worked OK. I tried for a bit and didn't get any errors, the functions were returning properly, but it just didn't actually try and fetch the requested page for some reason. Figured I'd wait for 3.0 and try again.

    Awesomium on the other hand caused a crash, didn't bother trying too hard to get that one to work as I don't think it's worth it at that price.
     
  15. JeDi

    JeDi

    Joined:
    Jun 16, 2010
    Posts:
    52
    I'm also trying to get Berkelium to work as a Unity plugin, and created a simple C interface on top of the SDK.

    The C functions are called correctly, but there seems to be a problem with the Berkelium message loop. I derived a Berkelium::WindowDelegate class, and correctly assign it to a newly created Berkelium window, but none of its functions are ever called.

    I am going to try using the latest Awesomium lib now, as a proof of concept, but I really want to get Berkelium to work because of its MIT license.

    Does anyone experience the same problems as me? As I said, the Berkelium functions don't give errors, but the delegates are never called. There is a chrome.log file, but it is empty.
     
  16. niosop2

    niosop2

    Joined:
    Jul 23, 2009
    Posts:
    1,059
    That's the exact same thing I was getting. No errors, but no delegates ever get called. Looking at the apache logs of a server I tried to hit, it looks like it never even tried to load the page.
     
  17. JeDi

    JeDi

    Joined:
    Jun 16, 2010
    Posts:
    52
    I found the reason it wasn't working. By looking at the Berkelium source code, I saw that the berkelium executable is actually run as an external process, and the process never showed up in the task manager.
    I then built a (standalone) release from my unity project and copied all berkelium files to the executable's directory. Et voila! It worked!

    I did some searching on this forum, and found that for the editor, the executables had to be placed in the editor's directory (which is quite annoying). I thought it would be the asset directory, because I created a log file in my code and that was where it was placed...

    So if you place all Berkelium binaries in the editor's directory, and in the executable's directory when you release your project, it will work.

    I have some other things to do today, but I will update this thread when I make progres.

    Greetz,
    JeDi
     
  18. niosop2

    niosop2

    Joined:
    Jul 23, 2009
    Posts:
    1,059
    Hmm, I had been testing standalones w/ no luck. I'd be interested to see your code if you don't mind sharing.
     
  19. reissgrant

    reissgrant

    Joined:
    Aug 20, 2009
    Posts:
    726
    If you're using an older version 1.0 that was released under GPL then there is no licensing costs. Sure, you won't have HTML5 support, but basic browser plugins will work just fine.
     
  20. Dreamora

    Dreamora

    Joined:
    Apr 5, 2008
    Posts:
    26,601
    Yeah but I don't want to create GPL games and thats the requirement if you work with a GPL library.
     
  21. reissgrant

    reissgrant

    Joined:
    Aug 20, 2009
    Posts:
    726
    My mistake, Awesomium version 1.0 was actually released under a creative commons license:
    "Attribution - NonCommercial - ShareAlike 3.0 United States" And yes, commercial is not an option.
     
  22. JeDi

    JeDi

    Joined:
    Jun 16, 2010
    Posts:
    52
    Don't worry about the license. I am creating a wrapper for Berkelium, not Awesomium. Berkelium has a BSD license, so I don't think there's a problem to use this even in commercial products.

    I will share the code when it is matured a bit. I just did some quick tests to see if the web pages are rendered, but I'm still using the SetPixels method to update the texture. I will probably switch to using OpenGL code, so I can optimize rendering using the dirty rectangling and scroll buffers that Berkelium provides.

    I will continue working on this plugin on Wednesday, because I have to attend a workshop tomorrow.
     
  23. reissgrant

    reissgrant

    Joined:
    Aug 20, 2009
    Posts:
    726
    JeDi, you can still use dirty rectangling with setpixels. It won't be as fast as opengl but you can at least use directx; and as long as your whole screen isn't updating, the framerates are still respectable. My code for rectangle rendering using Awesomium is:

    Code (csharp):
    1. void setPixelLoopRect()
    2. {
    3.     //set a block of only the pixels that have been changed
    4.     m_Texture.SetPixels (returnRectX(), returnRectY(),returnRectWidth(),returnRectHeight(),m_Pixels_rect,0);
    5.  
    6.  }
    7.  
    8. void updateTexture()
    9. {
    10.     if(isDirty()) // webpage dirty?
    11.     {  
    12.         setPixelLoopRect();  // set the new pixel values
    13.         m_Texture.Apply(); //  apply the texture changes to video card
    14.     }  
    15. }
    If you need C++ code just ask.
     
  24. JeDi

    JeDi

    Joined:
    Jun 16, 2010
    Posts:
    52
    Thanks for the tip. I will have a look at the Unity texture API, I didn't know that was possible. This is my very first time working with Unity...

    Maybe I'll even implement both ways: using SetPixels for when using DirectX and using OpenGL calls otherwise. Then we can do some speed comparisons.
     
  25. JeDi

    JeDi

    Joined:
    Jun 16, 2010
    Posts:
    52
    I released my first attempts at this plugin at http://research.edm.uhasselt.be/~nve/OSMA/UnityBerkeliumPlugin.zip

    The plugin still only has basic functionality, but I am actively working on it as we speak. This release is just proof that I am actually getting some results ;)

    The zip-file contains Berkelium, the source code and vs2008 solution of the plugin, a Unity test project and a test release so people without Unity Pro can see it working.


    Next things on my list is implementing support for scrolling, and caching the dirty rectangles to support partial updates using SetPixels (see reissgrant's comment above). After that, I will have a look at binding keyboard input.

    All contributions and comments are more than welcome of course!

    Greetz,
    JeDi


    Edit: I just realized that this thread is about Awesomium, not Berkelium. I opened a new thread here. We can continue discussing this plugin there.
     
  26. psyclone

    psyclone

    Joined:
    Nov 17, 2009
    Posts:
    245
    http://support.awesomium.com/kb/licensing/licensing-overview