Are events handled in non main thread, because I am initializing a scene in one and if I reinit the same scene by loading from xml-file, there is a high chance that it will crash somehow. It might actually lose textures etc.
Basicly I am doing something like this:
// clear old map, remove children
Urho3D::Node* sceneNode = scene_->GetChild("scene", true);
if (sceneNode)
sceneNode->GetParent()->RemoveAllChildren();
ResourceCache* cache = GetSubsystem<ResourceCache>();
// Technically add same nodes from xml-file.
XMLFile* file = cache->GetResource<XMLFile>("newmap.xml");
scene_->InstantiateXML(file->GetRoot("scene"), Urho3D::Vector3::ZERO, Quaternion());
map_->GenerateMapFromScene(scene_->GetChild("Map", true));
Also inside generatemap, I am going through the vertexbuffer-data. The resourcecache might somehow cause some weirdness when I am deleting stuff from scene, and basically instantly adding same stuff few lines later, which is not that good idea. Anyways I will try to isolate the crash a bit better tomorrow and hopefully manage to reproduce it with smaller amount of code. It could just be my horrible spaghetti code somewhere leaking memory/pointers pointing to unreached memory and causing tons of problems.
I am not even sure which systems are using extra threads, but it seems the crashes are mostly happening from worker threads, . Also the problem is, that this doesn’t happen on every execution, it just sometimes happens or crashes in various ways.