Quantcast

Jump to content

» «
Photo

Object Deletion Issues Arise :(

4 replies to this topic
HadesOfGTA
  • HadesOfGTA

    Player Hater

  • Members
  • Joined: 25 Jun 2013

#1

Posted 25 June 2013 - 12:05 AM

CODE
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?

nixolas1
  • nixolas1

    Creator/Destroyer

  • Members
  • Joined: 23 Dec 2008
  • None

#2

Posted 25 June 2013 - 02:28 PM

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.

HadesOfGTA
  • HadesOfGTA

    Player Hater

  • Members
  • Joined: 25 Jun 2013

#3

Posted 26 June 2013 - 12:33 AM

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.

AgentWD40
  • AgentWD40

    GLITCHED

  • Members
  • Joined: 02 May 2009
  • Philippines

#4

Posted 26 June 2013 - 03:22 PM Edited by hardsty1e, 26 June 2013 - 04:38 PM.

QUOTE (HadesOfGTA @ Wednesday, Jun 26 2013, 00:33)


@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

HadesOfGTA
  • HadesOfGTA

    Player Hater

  • Members
  • Joined: 25 Jun 2013

#5

Posted 08 July 2013 - 02:42 AM Edited by HadesOfGTA, 08 July 2013 - 03:02 AM.

Ok, still having issues.. dont know why.. if simple native can do it, i should be able too.

Here is the code:
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?




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users