Memory issue with Marmalade Client

Options
deevo
deevo
edited October 2013 in Native
Hi,

I am very stuck with a native bug - I am getting random crashes in my Marmalade (Version 6.2) program whenever I receive consecutive operations that contain a lot of arrays for parameter value.

For example on the server side I have:

[code2=csharp]int[] some_int_array1 = new int[50] { .....stuff in int array } ;
// a bunch of int arrays 2-29
int[] some_int_array30 = new int[50] { .....stuff in int array } ;

response.Parameters.Add((byte)0, 30); // the number of arrays
response.Parameters.Add((byte)(1), some_int_array1);
// add int arrays 2-29 to response
response.Parameters.Add((byte)(30), some_int_array30);[/code2]

Then on the client side I have this:

[code2=cpp]int count = (ExitGames::Common::ValueObject<int>(operationResponse.getParameterForCode(static_cast<nByte>(0)))).getDataCopy();

for(int i=1; i<=count; i++)
{
const int* intArray = NULL;
intArray = (ExitGames::Common::ValueObject<int*>(operationResponse.getParameterForCode(static_cast<nByte>(i)))).getDataCopy();

// am not even doing anything with the intArray, I just get it then delete it

ExitGames::Common::MemoryManagement::deallocateArray(intArray);
}[/code2]

So if I have more than 1 such operations like the above (basically the client receives 2 or more such operations), then after about 2-5 seconds, I get an access violation in Marmalade which I have no debug info for.

This happens with BOTH versions of the client 3.2.2 AND 3.0.4.2

It does not matter if it an int array or an object array that is received. I tried with object array first and it causes crash which led me to believe maybe it has to do with memory fragments or something, then I tried int array and it still happens.

It DOES NOT happen if I receive only one such operation response, only if I receive 2 or more such operations responses containing the arrays. So 1 operation response = no crash, 2 or more = crash.
It DOES NOT happen if I receive JSON strings that encodes the arrays instead of the arrays themselves. So strings = no crash, arrays = random crash.

The only clue I am getting is when I use "delete[] intArray" instead of "ExitGames::Common::MemoryManagement::deallocateArray(intArray);" marmalade says something like "max alloc exceeded". But this only happens in client version 3.2.2 and I think am not supposed to use "delete[]" in version 3.2.2. This warning doesn't come up if I use "ExitGames::Common::MemoryManagement::deallocateArray(intArray);" like the examples suggest.

Since I do not have debug symbols for the photon client I have no clue why this is. My gut is telling me this has to do with some kind of conflict in memory management between Photon Native Client and Marmalade.

Any clues anyone?

Comments

  • Kaiserludi
    Options
    Hi deevo.

    The code that you have shared looks fine (although you could just send a jagged array of arrays from the server and read it out as 2d array on the client, instead of having a whole bunch of variables with an increasing counter in their names).

    Would you mind providing us with a minimal reproduction case for those crashes?
    Just take one of the demos from the Photon Marmalade Client SDK and change it in a way that one of the clients "plays server" and sends those arrays to another one by means of raiseEvent (those saving any server side modifications for a custom operation response).

    If you can reproduce the crash with one of the demos, please provide us with the modified demo.

    Then we can have a look into it and see, what goes wrong.
  • deevo
    Options
    Thanks for the reply Kaiserludi - I was actually using jagged array of arrays earlier, then that was causing problems so I changed to object arrays, then int arrays.
    However, I found the solution to this problem, which had nothing to do with the photon client or message types, and everything to do with how Marmalade manages its memory.
    Basically, Marmalade by default only allocates 32k to the stack, and I think due to the nature of these arrays being received, photon client library was probably doing a lot of allocations. So that is causing a stack overflow in Marmalade randomly.
    The way to fix this problem is to set this in the Marmalade .icf file:

    [S3E]
    SysStackSize=4000000

    Once this has been set, the random crashes have gone away.
    I hope anyone who works with Marmalade read this blog post:
    http://blog.yjpark.org/blog/2013/04/14/ ... -and-tips/

    Hopefully this can save you a few days of pain if you ever run into weird problems using Marmalade!
    Developing with Photon has been very pleasant, Marmalade on the other hand has always given me weird problems.
  • Kaiserludi
    Options
    This thread may also give some useful info about that issue:
    http://marmalade.inverseblue.com/viewtopic.php?f=4&t=12

    Especially the peace of info about windows phone is interesting.