iOS crashing after using WebCamTexture

For the longest time my app has been working without any issues and recently I noticed that it kept crashing after using the webcamtexture. This is the error I am getting in XCode;

malloc: *** error for object 0xebd5aa0: pointer being freed was not allocated

After I use the webcamtexture and store it using getPixels(), I then stop the cam and continue with my next page in the app but I have some Resources.unloadUnusedAssets around to clear up some textures but it seems when that gets called right after using the web cam, I receive the error above.

I have been trying so many different things to get this done but it seems to be crashing only after I do texture2d.setPixels(webcamtexture.getPixels()) followed by the Resources.unloadUnusedAssets();

This is very important and I need to get a fix for this asap.

PS. I am using Unity 4.6.3 and this issue does NOT occur in Unity 4.6.1

Thanks!

I’m experiencing the same thing - Unity 4.6.3. Also, the Webcam texture is actually flipped horizontally for me and seems to also have a small offset too. Very weird.

You should post an example project in the bug tracker so the Unity team notices it.

… Just tested it on 4.6.2p1 and that was the last version that works fine. The issues above also occur in Unity 4.6.2p2 and Unity 4.6.3.

Well for now I’m switching back to 4.6.1 so I don’t have to worry about this issue. I have other things that need to be worked on at the moment

lol no worries - I just submitted an example project (Case 674503) - hopefully it will get fixed soon. :slight_smile:

1 Like

Thanks !

Some news for this problem? I was forced to downgrade to 4.6.0 for now because of that !

Not yet. First, Unity usually send an email to verify that they have tested the example project and have have recreated the bug - after that point they will start to work on it. Unfortunately I haven’t received that yet so I assume they haven’t even started working on a fix.

I’ve found that Unity 4.6.2p1 is the last build with webcam functionality working reasonably well so I have had to roll back to that.

Yea I am back on 4.6.2p1 as well being that 5.0 still doesn’t have the issue fixed either. But 5.0 has many other things that mess up my project as well.

Yeah, its a little frustrating but not much we can do at this point. Unity 5 is pretty awesome on the whole but the worst thing about it so far is that baking light maps on big scenes doesn’t work yet - at least not on the 2 scenes I’ve tested on. Hopefully Unity fix all of these issues soon :slight_smile:

Hi guys!

We also have the issue where the WebCamTexture is flipped on iOS. In our case, it is vertically mirrored even though WebCamTexture.videoVerticallyMirrored says its not. I don’t know about your projects, but ours is landscape only which might be why the feed is vertically flipped instead of horizontally.

Anyway, we’ve tried the latest Unity version (4.6.3p3 as of now) and the issue is still there. Unfortunately we absolutely need to support x64 on iOS, so we can’t revert to previous versions of Unity.

Our last hope would be to completely ignore WebCamTexture.videoVerticallyMirrored on iOS and always flip the image but that feels like a kind of “duct tape” fix to me.

Got any suggestions?

Thanks!

I kind of solved the problem by adding a simple script to the gameObject(applied webTexture), and I am using Unity 5 for my project. It should work as well for 4.6.x.
The solution is simple, just create a new script called notDestroy, and add following code to it:

voidAwake(){
DontDestroyOnLoad (gameObject);
}

Then, attach it to the gameObject which is applied webCamTexture.
As a result, the gameObject will not be destroyed after switching to the next scene. I know it could not be a good solution for memory management, but it works.

By the way, the gameObject should not be under your main camera. It will be still destroyed with your main camera although you have that script.

Hey guys. This issue is triggered the first time you call WebCamTexture.Stop() if you’re using GetPixels() to get texture’s content. After calling Stop(), Unity frees internal image buffer, but doesn’t mark it NULL. So GC’ing WebCamTexture or calling Stop() again will crash the app, as well as calls to GetPixels() will write into already freed image, which might corrupt memory. There’s no good workaround - the only way is to never call Stop() and don’t GC WebCamTexture you’ve created. This affects both 4.6 and 5.0. For 4.6 you can downgrade to 4.6.2p1 (bug introduced in 4.6.2p2). We’re working on the fix, and targeting coming patch releases.

Hi guys,

I’ve received more info regarding the “WebCamTexture is flipped” issue: it seems like it occurs only when using Metal graphics API, so forcing to Open GL ES 3.0 solves the issue until there’s a proper fix.

Nope, happens to me on GL ES 2.0 too

Here’s what I’ve tested so far:

  • iPhone 4S

  • Open GL 2.0: WebCamTexture properly displayed on both landscape right & left

  • Open GL 3.0: same

  • Metal: same

  • iPhone 5S

  • Open GL 2.0: WebCamTexture properly displayed on both landscape right & left

  • Open GL 3.0: same

  • Metal: WebCamTexture always vertically mirrored (videoVerticallyMirrored always returns false)

  • iPhone 6

  • Open GL 2.0: WebCamTexture properly displayed on both landscape right & left

  • Open GL 3.0: same

  • Metal: WebCamTexture always vertically mirrored (videoVerticallyMirrored always returns false)

It doesn’t work on portrait nor portrait upside down, though. That might be why you still have the issue.

Ah, possibly - my setup is actually in Portrait mode. :slight_smile:

  • Mel

I’ve noticed that the image is always flipped in Portrait/Upside Down mode on all devices and on all Graphics API. I’m installing 4.6.2p1 at the moment to see if that was the case in this version, too.

1 Like

I believe 4.6.2p1 is the latest build that’s workable , thats what I’m using right now at least! :slight_smile:

Hmm… I still have the issue 4.6.2p1… I’ve attached the script I’m using for testing if you want to compare with yours. :slight_smile:

2042260–132530–WebCamFeed.cs (736 Bytes)