Hello Guest

Author Topic: multiplatform memory issues  (Read 10239 times)

andremaia

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 5
    • View Profile
multiplatform memory issues
« on: May 13, 2013, 06:01:33 pm »
Hi

i'm using 2D toolkit for an iOS universal app and i'm having some memory issues when dealing with multiplatform support for the sprite collections.
I'm creating an sprite collection with support for the 3 platforms (1x, 2x,4x). It works great but when I compile the project and look to the log file generated by unity i can see that the 3 atlas textures are being used and loaded by unity.

Is there any way that I can choose to load only one of the textures in runtime when I check the screen resolutions?

cheers

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: multiplatform memory issues
« Reply #1 on: May 13, 2013, 10:08:32 pm »
What log file are you looking at?

andremaia

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 5
    • View Profile
Re: multiplatform memory issues
« Reply #2 on: May 14, 2013, 07:54:09 am »
the log file in the editor:
http://docs.unity3d.com/Documentation/Manual/LogFiles.html

"Used Assets, sorted by uncompressed size:
 32.0 mb    71.9% Assets/atlas/test Data/test@4x Data/atlas0.png
 8.0 mb    18.0% Assets/atlas/test Data/test@2x Data/atlas0.png
 2.0 mb    4.5% Assets/atlas/test Data/test@1x Data/atlas0.png
..."

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: multiplatform memory issues
« Reply #3 on: May 14, 2013, 09:13:43 am »
The files will be included in your build - isn't it expected? That is the only way you can pick one and load at runtime...

andremaia

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 5
    • View Profile
Re: multiplatform memory issues
« Reply #4 on: May 14, 2013, 10:04:12 am »
so when it's chosen the platform to use in Awake() like:

if(Screen.width<960)
         tk2dSystem.CurrentPlatform = "1x";
      else
         tk2dSystem.CurrentPlatform = "2x";

it's only loaded one of the atlas textures into memory??

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: multiplatform memory issues
« Reply #5 on: May 14, 2013, 10:11:52 am »
Yes, but -

i. Your tk2dSystem.CurrentPlatform call MUST run before everything else. Run it in an empty scene to be absolutely sure. If you must have the script in the same scene, make sure the script execution order is set up that your script runs before everything else.

ii. If you're using Unity 4.0 or 4.1, there is a really really nasty bug in there that causes the last used texture to be loaded when it shouldn't be. The bug report has been acknowledged by Unity engineers and they are fixing it, but I've not got an update if this will be fixed in Unity 4.2. There is a workaround to this, email support if you're affected.


andremaia

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 5
    • View Profile
Re: multiplatform memory issues
« Reply #6 on: May 14, 2013, 10:27:38 am »
ok.
don't really get point ii) - what do you mean with "last used texture to be loaded"?

one last thing:
should I check the sprite collection as "Loadable asset"?

thanks :)

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: multiplatform memory issues
« Reply #7 on: May 14, 2013, 10:32:22 am »
ii. This is only relevant if your using those 2 versions of Unity - basically, Unity was incorrectly saving the texture that you see in the viewport into the built game as the default.

No you don't need to set "Loadable asset"

Dgizusse

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 21
    • View Profile
Re: multiplatform memory issues
« Reply #8 on: May 14, 2013, 02:31:25 pm »
ii. If you're using Unity 4.0 or 4.1, there is a really really nasty bug in there that causes the last used texture to be loaded when it shouldn't be. The bug report has been acknowledged by Unity engineers and they are fixing it, but I've not got an update if this will be fixed in Unity 4.2. There is a workaround to this, email support if you're affected.

In order to get around this bug would it be best to set the platform in editor to 1x and go back and save every scenes before building?

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: multiplatform memory issues
« Reply #9 on: May 14, 2013, 03:06:21 pm »
No, you don't have to.

If you were to set the platform to 1x and built, the 1x textures would be preloaded. You don't have to save the scene manually for it to take effect.
Its the least of the evils compared to all the other methods, I guess, but I have a really much lower level hack in place to work around this.

HACK ALERT
This is a nasty hack to work around a much much nastier bug in Unity, so don't be alarmed by its nastiness :)

1. Make a build script to build your game. You probably already have one.
This is important, otherwise you'll get really annoyed having to do the next step every time you build. Its really simple - refer to http://docs.unity3d.com/Documentation/ScriptReference/BuildPipeline.BuildPlayer.html

2. Before calling build player, create an empty file in your project directory (i.e. outside assets, where libraries, etc. live). The file should be called tk2dOverrideBuildMaterial. No extension.

3. Now build your project - you should see all your scenes load in while it is building, but everything will be white.

4. After your project has built, delete the file, and reload your scene. It should appear correctly now (if it doesn't a restart of Unity will certainly fix it).

You can automate the whole process, so you won't have to create & delete the file every time.

Dgizusse

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 21
    • View Profile
Re: multiplatform memory issues
« Reply #10 on: May 14, 2013, 04:00:14 pm »
Nice, that's pretty clever!

(BTW, I'm the guy who sent you the LoadPNG code about a month ago by email and looking at the hack code, I think that would have broken this hack when loading from PNGs because of the code I've added in tk2dSpriteCollectionData::Init() in the tk2dSystem.OverrideBuildMaterial if... I did not really realize what was going on in there at the time.)

Thanks!

andremaia

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 5
    • View Profile
Re: multiplatform memory issues
« Reply #11 on: May 14, 2013, 08:48:12 pm »
nice!
thanks for that :)