- Home /
Server crashes accessing the same asset on 2nd instance
I'm at my wit's end with this problem:
I have a server and a client. There are 2 maps, called "Nubek" and "Ruins". There are 3 "game modes" or server types called "Town", "Match" and "FFA". The server is running on Ubuntu 13.04 x64 with Linux headless mode x64. Starting the server twice with the same map leads to the following results:
Locally (Windows x64):
Town: Working
Match: Working
FFA: Working
Live server (Ubuntu 13.04 Linux headless mode x64):
Town: Working
Match: Working
FFA: Fail on 2nd instance start, logs stop at Resources.Load("Maps/Nubek")
Here's a screenshot on the live server starting the server with the same map twice:
After this I thought "What are the differences?" and "Why is the instance crashing 1 second after the start?". So I checked the logs and they stop at Resources.Load("Maps/Nubek") on the second FFA instance. It's a single binary started multiple times on the linux server with the same data folder. This was normally never a problem. Any idea what might be causing it? Anyway, this was the main problem. But here comes something weirder:
One thing that I suspected to be the cause of the Resources.Load() crash was my "DestroyServerAssets" function which is called after map load on the first instance.
// DO NOT CALL THIS IN THE EDITOR
private void DestroyServerAssets() {
LogManager.General.Log("Going to destroy unneeded server assets");
// Remove all textures
var allTextures = Resources.FindObjectsOfTypeAll(typeof(Texture));
LogManager.General.Log(allTextures.Length.ToString() + " textures loaded, going to destroy.");
foreach(var obj in allTextures) {
Destroy(obj);
}
LogManager.General.Log("Textures destroyed.");
// Remove all audio clips
var allAudioClips = Resources.FindObjectsOfTypeAll(typeof(AudioClip));
LogManager.General.Log(allAudioClips.Length.ToString() + " audio clips loaded, going to destroy.");
foreach(var obj in allAudioClips) {
Destroy(obj);
}
LogManager.General.Log("Audio clips destroyed.");
// Remove all materials
var allMaterials = Resources.FindObjectsOfTypeAll(typeof(Material));
LogManager.General.Log(allMaterials.Length.ToString() + " materials loaded, going to destroy.");
foreach(var obj in allMaterials) {
Destroy(obj);
}
LogManager.General.Log("Materials destroyed.");
// DO NOT DELETE THE MESHES, YOU WILL GET PROBLEMS ON THE SERVER
}
Don't ask me why the first instance would interfere with the assets of the 2nd instance, it doesn't even make sense to me, but that was my first idea. So I tried commenting out the call to DestroyServerAssets() and checked it again. The result: Now if I start a 2nd instance with the same map, it's not the 2nd instance crashing anymore but rather the first instance that crashes. Now the crash happens on all game modes.
I am using Unitypark / uZone for the instance management, however I am 99% sure this is not related to any library problems because the call that fails is Resources.Load() in the first problem I described.
Does Destroy()'ing game objects in a running Unity instance cause any problems for a 2nd instance using the same assets? As far as I know Destroy() is not an "inter-instance" call and should only destroy the loaded asset in RAM only for the calling instance, or am I wrong? What's going on here?
You should avoid destroying assets and destroy instances ins$$anonymous$$d. If multiple objects are derived from the same asset, destroying the asset may cause problems to the instances.
Destroying an instance should not affect other instances.
As I understand it, Garbage collection should automatically free up the RA$$anonymous$$ previously taken by resources which are no longer referenced.
If I remove the call to DestroyServerAssets() the behaviour becomes even weirder, see the 2nd part of the problem where I described what happens if the call does not happen. Then every instance crashes on loading the same map, contrary to the first problem where loading the same map worked in 5 / 6 cases.