Jump to content
    1. Welcome to GTAForums!

    1. GTANet.com

    1. GTA Online

      1. Los Santos Drug Wars
      2. Updates
      3. Find Lobbies & Players
      4. Guides & Strategies
      5. Vehicles
      6. Content Creator
      7. Help & Support
    2. Red Dead Online

      1. Blood Money
      2. Frontier Pursuits
      3. Find Lobbies & Outlaws
      4. Help & Support
    3. Crews

    1. Grand Theft Auto Series

      1. Bugs*
      2. St. Andrews Cathedral
    2. GTA VI

    3. GTA V

      1. Guides & Strategies
      2. Help & Support
    4. GTA IV

      1. The Lost and Damned
      2. The Ballad of Gay Tony
      3. Guides & Strategies
      4. Help & Support
    5. GTA San Andreas

      1. Classic GTA SA
      2. Guides & Strategies
      3. Help & Support
    6. GTA Vice City

      1. Classic GTA VC
      2. Guides & Strategies
      3. Help & Support
    7. GTA III

      1. Classic GTA III
      2. Guides & Strategies
      3. Help & Support
    8. Portable Games

      1. GTA Chinatown Wars
      2. GTA Vice City Stories
      3. GTA Liberty City Stories
    9. Top-Down Games

      1. GTA Advance
      2. GTA 2
      3. GTA
    1. Red Dead Redemption 2

      1. PC
      2. Help & Support
    2. Red Dead Redemption

    1. GTA Mods

      1. GTA V
      2. GTA IV
      3. GTA III, VC & SA
      4. Tutorials
    2. Red Dead Mods

      1. Documentation
    3. Mod Showroom

      1. Scripts & Plugins
      2. Maps
      3. Total Conversions
      4. Vehicles
      5. Textures
      6. Characters
      7. Tools
      8. Other
      9. Workshop
    4. Featured Mods

      1. Design Your Own Mission
      2. OpenIV
      3. GTA: Underground
      4. GTA: Liberty City
      5. GTA: State of Liberty
    1. Rockstar Games

    2. Rockstar Collectors

    1. Off-Topic

      1. General Chat
      2. Gaming
      3. Technology
      4. Movies & TV
      5. Music
      6. Sports
      7. Vehicles
    2. Expression

      1. Graphics / Visual Arts
      2. GFX Requests & Tutorials
      3. Writers' Discussion
      4. Debates & Discussion
    1. Announcements

    2. Support

    3. Suggestions

Object Deletion Issues Arise :(


HadesOfGTA
 Share

Recommended Posts

 

	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

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

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

 

 

@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 Shifty41s_beerhatsmilie2.gif

Edited by hardsty1e
Link to comment
Share on other sites

  • 2 weeks later...
HadesOfGTA

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 by HadesOfGTA
Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • 1 User Currently Viewing
    0 members, 0 Anonymous, 1 Guest

×
×
  • Create New...

Important Information

By using GTAForums.com, you agree to our Terms of Use and Privacy Policy.