Unity randomly refuses to read a valid JPEG file.

Heyo. I have this weird problem where Unity randomly refuses to read a JPG file.

I’m streaming MJPEGs from an IP cam and putting them up as a texture on a plane. Every now and then I get a question mark displayed, which indicates that the received image could not be read. This seems to be completely random (and there’s nothing else in the scene except for that plane).

I verified that the stream from the cam is valid and it’s not the cam’s or the network’s fault - the stream works perfectly fine in a browser, no hiccups and corrupted frames. The cam’s plugged in via an ethernet cable directly to my PC (it was plugged into a router previously, no change in behaviour).

I started writing all received JPGs to disk and modifying their filenames depending on whether they were displayed in Unity or not. They ALL open perfectly well in Windows’ image browser, Photoshop or whatever. I even opened them in hex editor to make sure they all start with FFD8 and end with FFD9, and they all do.

However, when I drag an image that wasn’t displayed properly as an asset into Unity, I get an error: “File could not be read.”

What’s even weirder, is that this is a part of a larger project that worked fine on 2 separate PCs for something like two months, when suddenly one started getting hiccups and question marks. The other one worked fine, then started presenting the same problems two weeks later. Nothing in the app itself changed.

I’m really stumped here and I’d appreaciate any and all help. Thanks in advance.

It’s a common error with a red question mark “?”, when you didn’t receive the byte data completely.
This plugin might be useful and worth to have a look.

FM Exhibition Tool Pack | Forum

Provides demos of in-game view/live video, audio streaming solution. All codes are written in C# and you can freely customise for your own project.

Supported Platforms: iOS/Android/Mac/PC