HadesOfGTA Posted June 25, 2013 Share Posted June 25, 2013 while(!ourObjects.empty()) { GetNetworkIdFromObject(*ourObjects.back(), &objID); SetObjectExistsOnAllMachines(*ourObjects.back(), true); SetNetworkIdExistsOnAllMachines(objID, true); GetObjectModel(*ourObjects.back(), &objModel); MarkModelAsNoLongerNeeded(objModel); Object mObj = *ourObjects.back(); while(DoesObjectExist(*ourObjects.back()) && mObj.IsValid()) { FreezeObjectPosition(*ourObjects.back(), false); SetObjectVisible(*ourObjects.back(), false); DeleteObject(ourObjects.back()); Wait(50); } Wait(50); delete ourObjects.back(); ourObjects.pop_back();} ourObjects is a vector that I use to store object id's. When I am in a MP game by myself, they delete fine. When I am not, the game crashes when I try to delete. Any idea's what I am doing wrong? Link to comment Share on other sites More sharing options...
nixolas1 Posted June 25, 2013 Share Posted June 25, 2013 The reason of the crash is that you dont have permission to delete the object, cause you have lost the ownership of it, so the object dosnt get deleted and you are running an infinite while loop, which freezes the game. Never run infinite while loops unless youre 100% certain that it will end. You should add a counter, and make it end if the counter is larger than 100 etc. You need to use RequestControlOfNetworkID to gain control over the object again. And maybe SetNetworkIdCanMigrate. EDIT: its also good practice to add DoesObjectExist checks, cause the game crashes if you interact with non-exsisting objects. cheers, nix. Link to comment Share on other sites More sharing options...
HadesOfGTA Posted June 26, 2013 Author Share Posted June 26, 2013 Source: http://pastebin.com/5YQWyCdm @nixolas1 I actually implemented object existence checks last night and by default, Network IDs are set to not migrate on object creation. By all means they should delete! I was thinking perhaps I was overlooking something else but I removed the object spawning code and everything works flawlessly. I posted the entire thread cpp file above at pastebin. Link to comment Share on other sites More sharing options...
AgentWD40 Posted June 26, 2013 Share Posted June 26, 2013 (edited) @nixolas1 I actually implemented object existence checks last night and by default, Network IDs are set to not migrate on object creation. By all means they should delete! I was thinking perhaps I was overlooking something else but I removed the object spawning code and everything works flawlessly. I posted the entire thread cpp file above at pastebin. I was trying to make custom point couple weeks ago lol but instead I just made a permanent coordinate point. alot of people had some fun with it. impressive mod by the way Edited June 26, 2013 by hardsty1e Link to comment Share on other sites More sharing options...
HadesOfGTA Posted July 8, 2013 Author Share Posted July 8, 2013 (edited) Ok, still having issues.. dont know why.. if simple native can do it, i should be able too. Here is the code: std::stack <Object*> spawnedObjects;b8 CustomFiberThread::OwnRequestControlOfNetworkId(u32 netid){u32 attemptcounter = 0;if (NetworkGetGameMode() == SINGLE) { return true;}SetNetworkIdCanMigrate(netid, true); while (!HasControlOfNetworkId(netid) && ((attemptcounter++) < 100)) { RequestControlOfNetworkId(netid); Wait(0);} return RequestControlOfNetworkId(netid);}Object CustomFiberThread::CreateObjectTemp(Scripting::eModel objmodel){Object obj;u32 onetid;RequestModel(objmodel);while(!HasModelLoaded(objmodel)){ Wait(0);}CreateObject(objmodel, 0,0,0, &obj, true);MarkModelAsNoLongerNeeded(objmodel);if (DoesObjectExist(obj)) { FreezeObjectPosition(obj, true); GetNetworkIdFromObject(obj, &onetid); SetNetworkIdExistsOnAllMachines(onetid, true); SetNetworkIdCanMigrate(onetid, false);}return obj;}void CustomFiberThread::DeleteAllSpawnedObjects() {u32 objnetid;eModel objMod;Ped ped;while (!spawnedObjects.empty()) { if(DoesObjectExist(*spawnedObjects.top())) { GetObjectModel(*spawnedObjects.top(), &objMod); GetNetworkIdFromObject(*spawnedObjects.top(), &objnetid); if (OwnRequestControlOfNetworkId(objnetid)) { if (IsObjectAttached(*spawnedObjects.top())) { DetachObject(*spawnedObjects.top(), true); } MarkModelAsNoLongerNeeded(objMod); u32 attemptcounter = 0; while((attemptcounter++) < 20) { DeleteObject(spawnedObjects.top()); Wait(0); } } } spawnedObjects.pop();}} I create the Object with CreateObjectTemp, store it in a stack called spawnedObjects. I then try to delete my objects with the above function in MP Freemode, and they refuse to delete. By all means, it should delete! I create the object with migration as false, but even if that does somehow get lost, it should still DELETE!! Especially when it is just me in a private freemode. EDIT: I just threw in some PrintStringWithLiteralStringNow's to see what parts of the deletion code it was entering, and it absolutely will NEVER enter OwnRequestControlOfNetworkId function. I know this function works as I use it in other code and it ALWAYS enters. Why are these objects not becoming available to me? Edited July 8, 2013 by HadesOfGTA Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now