Problems with WWW and memory

Hi!

My game saves player highscore, players coins etc. to the server. I’ve basically used the Server Side Highscores.

http://wiki.unity3d.com/index.php?title=Server_Side_Highscores

So I got different functions for the saves and they save the info one by one. Something like this…

function SavePlayerName()
{
    var namePost = WWW(addName_url);
    yield namePost;
    if (namePost.error)
    {
        print(namePost.error);   
    }
    SavePlayerCoins();
}

function SavePlayerCoins()
{
    var coinsPost = WWW(addName_url);
    yield coinsPost;
    if (coinsPost.error)
    {
        print(coinsPost.error);   
    }
}

My games is also for Android and iOS devices. Everything works with them but when I build the same game/code on Windows Phone - it seems that all the information is not updating. In Visual Studio’s Debug Log I noticed some memory issues. Does these WWW add up on each other? Taking more and more memory? Since my game is checking coins many times in different places in the game. Any ideas what to do?

Could you copy-paste those “memory issues” from the log, you give very little information, so it’s hard to understand what’s wrong. But WWW does work on Windows Phone.

I forgot to mention that the game and code also works when I play it on Unity Editor and have the Windows Phone set as platform.

I made new project with just GUI and 3 buttons to narrow down the problem.

The buttons are simply:

Add coin +1
See how many coins player has
Give the player new ID

Again, it works on Unity editor, but not on my Nokia Lumia 635.

Here’s what the Visual Studio debug log gives:

The thread 0x4a0 has exited with code 259 (0x103).

I noticed that “the memory issues” before had to do something with Mobile/Diffuce textures not supported.

Otherwise I have debug logged all the URL’s I use for example:

Add coin +1
http://mygamesite.net/mygame/addCoins.php?id=1665b319c4e581b63332849bc3c6b9eb3a329c07&amount=1&hash=8593d216ce6dccb74ebea41e2b9649f5

See how many coins player has
http://mygamesite.net/mygame/bank.php?uid=1665b319c4e581b63332849bc3c6b9eb3a329c07

If I take these URL’s from Visual Studio’s Debug Log and copy paste them into Web Browser. All the values are working. In this example of course they are not the real ones.

Since the new project only has GUI and this WWW. I quess it’s not about the memory. But could it be that these URL values are too long for Windows Phone? If so what could I do?

Again game works on iOS, Android and Unity player.

I highly doubt it’s URL length. Do you have a player log or VS output to show us? Does the application crash, or does the WWW never complete?

No it doesn’t crash. I posted the VS output for you. And the WWW seems to complete since it gives values.

Which Unity version is this, there was a bug in 4.3 version, that headers[“Content-Type”] = “application/x-www-form-urlencoded” was not being set for WWW, thus the request was invalid. Could that be the same issue you’re having, please post the full UnityPlayer.log, because you’re providing too little information.

I got the log as PM, because it contains sensitive private information. Unity version is 4.6.1f1, there aren’t any errors printed. It just shows that the result of getting coin amount from the server is always 0.

My question for you: did you try debugging it and seeing where it fails? Does the WWW return zeroes, or does it not return anything and variable stays uninitialized so it just prints zeroes?

I think it returns the zeroes. I didn’t see any errors printed.

I posted you the script I’ve used if you can see anything wrong there?

Script looks ok. I’d suggest attaching a debugger to server side, and checking what your server returns.

I tested this with the Nokia Lumia device and debugged the server results. It seems that that the “buttons” (or WWW) only work once with Lumia. So if I press the buttons:

Button > Add new ID (works)
Button > Add one coin +1 (works)
Button > Bank (works)

It will add new ID, add one coin and show result 1 in the bank.

But it won’t let me do anything twice.

So if I press the “Add one coin” button again, nothing shows in the server’s Log. It’s not adding any coins. If I try to see the bank amout, it will show the result that was used first. In this case it stays at 1. When it should be 2 after the “Add once coin” been pressed second time.

When it showed zero before, it was because of the order I tested the buttons was different.

Button > Add new ID (works)
Button > Bank (coins are 0) (works)
Button > Add one coin +1 (works)
Button > Bank (not working anymore… server log sees nothing… shows me 0)

It will then show that coins are zero, because the “Bank button” was already used. The Add coin was pressed only after that so in this case it stays at zero. In reality the bank is 1 on the server because the Add one coin worked after that.

So the problem is that it will execute those WWW only once, after that it will show the first result whatever it was.

Button > Add new ID (works)
Button > Add one coin (works)
Button > Bank (works)
Button > Add one coin (nothing on the server log)
Button > Bank (nothing on the server log)
And so on…

Could this problem be with the device/game or with the server? If it’s with the server, how does it work with iOS, android and Unity Player?

It’s like it saves the result to certain part of memory, then when I call the function again it’s not doing it again, only shows the result it got the first time.

Hmm, that’s strange. So it looks like the phone is caching the result instead of connecting to the server again?

Google turned this up:

https://social.msdn.microsoft.com/Forums/windowsapps/en-US/1df95d3e-68c9-4351-822a-c2cfde380248/how-to-disable-caching-http-get-in-metro-app-i-am-using-ixmlhttprequest2?forum=winappswithnativecode#1df95d3e-68c9-4351-822a-c2cfde380248

Looks like it’s gonna do that by default, as long as the server says that the document is not expiring and you don’t specifically request it not to cache.

There are 2 workarounds suggested:

  1. Make server say that document expiration is 0 seconds;
  2. Add a www header field: headers[“If-Modified-Since”] = “Sat, 01 Jan 2000 00:00:01 GMT”;

Yes, got it working! Thank you very much! :slight_smile: