Mapbox SDK unity - Memory leaks? CPU usage high after exiting playmode?

Hey guys, been trying out the Mapbox SDK for unity which is available after signing up here:

And it seems to have some problems (it is beta, so yeah… gonna happen I suppose).

EDIT: See below post for possible resolution…

I started using it when it was beta 0.2 and it had an example of a slippy map where you could scroll around with your mouse (or mobile touchscreen) and view a map. Pretty decent little demo, but it had problems. It seems that after you go into playmode and use the slippy map example for a minute or two, then leave playmode, the editor continues to eat up CPU usage pretty bad, seems to get worse the more you use the demo.

I thought it must have been something I was doing wrong, and I tried for a while to locate any issues with the side of things I had created, but could not get to the bottom of it.

I downloaded the new version today (0.4) and tried it out, and it includes a new slippy map demo. Turns out though, lots of the functionality of the old demo was lost! Now the demo doesn’t do things it used to do, like keeping the map centered on the world origin to avoid floating point precision issues if you were to go far from the origin while scrolling. Also it doesn’t seem to delete the distant tiles, and keeps them around, making it very memory consuming. It does look nicer! They seem to have improved the quality of the terrain graphics and height mapping.

I noticed though, this new demo, it is even worse than the old one perhaps as far as performance goes, it has the same CPU eating problem also! The only way to make this go away, is to completely exit unity, and restart fresh, then after only playing a single time and exiting, it seems to start eating CPU for me. This gets progressively worse until it takes upwards of 99 percent of the processor, and unity becomes sluggish as can be.

So anybody else experience this issue with the SDK? Anybody figure out why/what causes this leak/problem? I haven’t dug in deep enough to find out, but before I do - maybe someone knows where to start?

I decided to port the old (better in my opinion) slippy map into the new SDK, it was pretty easy, and it still works like it used to, but again, still seems to have the CPU usage leak in the editor. I imagine this wouldn’t be a problem on real apps, where the app is closed and restarted rather than exiting and re-entering playmode and keeping “orphaned” variables/methods or whatever is going on, I’m guessing here… I really have no idea, and would love it if somebody has already had a chance to address this problem, or at least knows more about it, before I pull all my hair out trying to find out :smile:

PS, already brought this up to mapbox team through email, haven’t heard back…

I fixed it (sort of, see edit) by creating this method in Slippy.cs (the one from version 0.2) and this might also work for the new slippy map example:

        void OnApplicationQuit()
        {
            if (raster != null)
            {
                raster.Unsubscribe(this);
                rawpng.Unsubscribe(this);
                raster = null;
                rawpng = null;
            }
        }

EDIT: scratch that - does seem to still have problems beyond this, but doing that at least seems to make it happen less? I could be wrong and it makes no difference at all, and I’ve been lucky enough to run a handful of times without it happening as frequently.

I’d still love to hear if anybody else gets this problem, and if anybody else has gotten around it.

1 Like

I wish I could help. I am trying to get this SDK working myself. It’s odd you don’t hear anything from Mapbox.
I had the same issue. I sent them an email asking for assistance and heard nothing back.
I will be interested to hear if you, or one of the people on the forum sort it.
It’s a free SDK so I would encourage anyone to have a play with it.
Best of luck with the problem.

I gave up, and tried an alternative that worked much better…

In the interest of not dogging on mapbox I won’t name it here… but it is a unity asset that does this job very well with no leaks and is faster, more effective. :smile: