ImpromptuNinjas / UltralightSharp

Multi-platform .NET bindings to the Ultralight project.
Other
129 stars 17 forks source link

Frame load interrupted error message when using customized FileSystem instance #5

Open sofussts opened 3 years ago

sofussts commented 3 years ago

I am trying to implement my own FileSystem code, but I am not able to get the assets/index.html file to be displayed properly. The UltralightSharp.SafeDemo runs well when the default AppCore.EnablePlatformFileSystem is used. Next I try to use my own by setting the FileSystem:

    var assetsPath = Path.Combine(asmDir, "assets");
    //Safe.AppCore.EnablePlatformFileSystem(assetsPath);
    Ultralight.SetFileSystem(MyFileSystem.GetFileSystem(assetsPath));

When my own implementation of the FileSystem is set (basically, just my own implementation of the callback methods) , then nothing is shown in the UI for the URL "file:///index.html" and the view.SetFailLoadingCallback method reports:

    URL: file:///index.html, Description: Frame load interrupted, ErrorDomain: WebKitErrorDomain, ErrorCode: 102

See the attached file for details on how the MyFileSystem class is currently implemented. MyFileSystem.zip

Breakpoints in my code show that the FileSystemReadFromFileCallback is called as it is supposed to. I am able to load the data as UTF8 byte array and return the data (the test code that is commented out below shows that the data is loaded from the file into the string s) :

    fs.ReadFromFile = new FileSystemReadFromFileCallback((handle, data) =>
    {
        uint nRead;
        byte[] bytes = new byte[data.Length];
        if (ReadFile(handle, bytes, (uint)data.Length, out nRead, IntPtr.Zero))
        {
            data = new ReadOnlySpan<byte>(bytes);
            //string s = Encoding.UTF8.GetString(data.ToArray());
            return (long)data.Length;
        }
        return -1;
    });

After this method is done the FileSystemGetFileMimeTypeCallback method is called, where I set the returned result to the hardcoded mime type: "text/html" and return true.

After that the next thing that is logged is the reported error message. Is there some sample code that demonstrates how to build a custom FileSystem instance in c#? What is the problem causing the reported error message?

I am currently using ultralight-sdk-1.2.0-win-x64-min with the latest version of UltralightSharp from the master branch.

Tyler-IN commented 3 years ago

The UL# distribution includes a build of UL 1.2.0-beta - the API for stable may be different.

I'm unsure what the problem here is yet, but I'll address it for the UL# 1.2 stable release.

sofussts commented 3 years ago

Tested with UL v1.2.0-beta.2. Same behaviour and error as with the stable version.

Please note that when I try to test with the binaries distributed with the UltralightSharp SDK in the folder UltralightSharp-master\UltralightSharp.Core.WinX64\runtimes\win-x64\native, it seems that these are built for the AMD processor (or something else) so I get an error message when I try to use them:

System.BadImageFormatException: ' is not a valid Win32 application. (Exception from HRESULT: 0x800700C1)'

SupinePandora43 commented 1 year ago

Afaik it finally was fixed in 1.3