Seven Zip and Unity 5 [WebGL - HTML5]

Posted by DFortun81 on April 12, 2015, 2:29 p.m.

I'm attempting to use SevenZip for compression in a Unity 5 game that I'm working on. It works fantastically so far, however, when I attempt to compile the game for WebGL (HTML5), I keep getting a Data Error Exception when it runs. Initially, I thought there might be something wrong with the data file itself, so I made a really small project and reviewed the contents of the file, the arrangement of the bytes, and so on. This review proved that the file itself was not at fault.

When Unity creates a WebGL build, it converts just about everything into JavaScript ASM. I suspect that there might be something in the code that the converter was not expected or wrote in the wrong logical order. I will eventually figure out what's wrong and how to fix it, but I would absolutely love it if I could get some additional heads looking into this issue.

Attached is the sample project in question. If you run the project in the Unity editor (you may have to load the Test scene first) and look at the console output, there are results of the test as they are expected. They should all pass. If you compile the project to WebGL and then run that build in a browser, then you'll see the Data Error Exception print out when the bytes are supposed to be decompressed. (directly after the debug and right before the tests)

LZMA Compression Sample - Unity 5 Project

Alternatively, if I uncheck the box on the Main Camera object that says "Test Compressed Resource File", the uncompressed version of the file works without issue under all cases. The problem must lie with the SevenZip decoder and its compatibility with Unity's JavaScript ASM.

Comments

Alert Games 9 years, 7 months ago

Apologies if this is somewhat irrelevant, but I heard that 7zip is still less reliable than winrar compression is that still true?

flashback 9 years, 7 months ago

"Reliable" in what sense?

Alert Games 9 years, 7 months ago

I've heard that there are sometimes errors when building the archives. I've barely made any 7zip archives compared to winrar archives, but I'm guessing that this is probably no longer the case. (This is why I was mentioning that it may be a little off-topic)

As for the Unity 5 issue, it sounds like a problem with the decoder itself.

DFortun81 9 years, 7 months ago

I was thinking the same thing AG. I'll switch over to using WinRAR to see if I encounter the same issue.

DFortun81 9 years, 7 months ago

The Seven Zip library had initialization for non-static members in the decoding classes declared outside of the constructor. This behaviour is NOT detected by the JavaScript ASM cross-compiler and was the cause of my problem.

**Do NOT practice local variable initialization outside of a class method or constructor** - This may be valid behaviour in C# , but the cross-compiler will simply ignore it.

Fixed. :D

Alert Games 9 years, 7 months ago

Glad to hear it. Thanks for posting the solution!