Game with ComputeShader crashes after loosing focus and after reloading scene on Samsung s9

So I have game where computeshader calculates waves.( see attached youtube video)
Everything works in Editor and on my Xperia X Compact.
On Samsung S9 when I switch to another App the game freezes.( No button works, animation of sprite either freezes, or flickers.

First it started to happen when I switched ro other app and came back. Now I made the scene reload, using OnApplication Pause, so I load the scene again. Before loading I save the state of the field in array in singleton object. Then in the new scene I just make RWStructuredBuffer.SetData(savedData) to restore the state of my waves. But on Samsung S9 it freezes the game even if I set not stored, but freshly generated array.
Has anyone an Idea, what could be wrong?
PS. If I SetData without reloading scene or switching to other application or minimizing app, it works flawlessly.

Always look in adb logcat for clues.

Thank you for your reply, but in logcat no new records appears and no new mistakes, when problem occures.
samsung logcat

sony logcat

See if you can use Debug.Log() statements in and around all your onpause/onquit logic and isolate exactly where it is going south. it might be necessary to make the reload into a coroutine in order to properly restore it over a few separate frames and figure out which part is choking, and still get debug output on the logcat… not sure when that actually gets written out the USB port…

1 Like

It looks like I found the problem. I have kernel that calculates the average value of all neighbours.
For example right bottom neighbour:

float ifYL_W = 1.0 - step(Width-1, id.y); // is 1 when id.y is less then maximum y. So we have lower neighbours
float ifXL_W = 1.0 - step(Width-1, id.x);//  is 1 when id.x is less then maximum x. So we have  neighbours at right side.

neighborPixels += buffer[myPos + Width + 1].height * ifYL_W * ifXL_W;
numOfParts += 1 * ifYL_W * ifXL_W;

so I used positions in array, that are out of it range, but in the next line I just didn´t use them if they are out of range.
So I changed array index to zero in such cases and it helped.

neighborPixels += buffer[(myPos + Width + 1)* ifYL_W * ifXL_W].height * ifYL_W * ifXL_W;

Hope that it is possible to understand what I wrote. :slight_smile:

1 Like

Hopefully I solved the issue, but I already tried. I see, that everything goes south after I call buffer.SetData(), but not exactly right after this. I used text field to show the place, where am I in the script. and it shows " I am after buffer.SetData(), but not shows " I am before shader.Dipatch(). Anyway, thank you. Hope it will not return tomorrow.