Monday, 21 December 2015

Avoid memory leak in Unity3D when loading images

Recently I tried to make a picture player with Unity3D, should be easy... but is not...
It seems that Unity3D still has some problems regarding the memory leaks when accessing resources from local disk. I tried to use the basic way something like this:

var _texture2D = new Texture2D(1024, 1024, TextureFormat.RGBA4444, false);//this is initialised only once
void ShowPicture(string filePath)
byte[] fileData = File.ReadAllBytes(filePath);
Sprite sprite = Sprite.Create(_texture2D, new Rect(0, 0, _texture2D.width, _texture2D.height),;              
myImage.GetComponent<Image>().sprite = sprite;
Ok, this seems right, but it's not, because after a while the application crashes.
I tried to call GC.Collect(), but still the same result.
After a lot of attempts, the solution is to pass directly the texture:

    private IEnumerator LoadPicture(string file)
        WWW www = new WWW("file://" + file);
        yield return www;

The issue here is that the aspect ratio is not correct.

Friday, 13 November 2015

Ubiquiti mFi mini mPower wifi - ssh connection Raspberry Pi

How to connect to mFi mini mPower through command line:

1. You must know your mPower IP address. Let's say is (like my is..)

2. Open terminal window on Raspberry Pi:

3. Switch to root user:
> sudo su

4. Enter ssh command to connect with your mPower device, and specify the username of the mPower device
> ssh -l sorin
then set the password of the mPower device

5. Now you should be connected to your mPower device, see your settings:
> cd cfg
> cat config_file

6. Change switch relay to on (0 - off, 1 - on):
> cd /proc/power/
> echo 1 > relay1

7. See that your switch has changed state:
> cat relay1
> 1 --- you should see this value