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
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.
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
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.
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.
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.
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.
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.