samp-incognito / samp-streamer-plugin

Streamer Plugin for SA-MP (San Andreas Multiplayer)
Apache License 2.0
231 stars 92 forks source link

AttachDynamicObjectToObject bug #202

Closed Tagic closed 7 years ago

Tagic commented 7 years ago

I made command that create two dynamic objects, I attach them with AttachDynamicObjectToObject and it works, but when I leave stream radius and come back the attach object is not streamed in(loaded) it disappears. Streamer only load the main object. And it works only when I type command for the first time if I type command again streamer only create me the main object.

My code:

 GetPlayerPos(playerid, X, Y, Z);
 new Mainobject = CreateDynamicObject(19632,X, Y, Z+2,0.000000,0.000000,14.900031);
 new Attachobject = CreateDynamicObject(19614,X, Y, Z-100,0.000000,0.000000,0.000000);
 AttachDynamicObjectToObject(Attachobject,Mainobject,0.009999,-0.220000,-0.599999,0.000000,0.000000,180.000015);
samp-incognito commented 7 years ago

It could be an issue with YSF, but I don't know. Make sure that plugin is up to date.

Edit: It could also possibly be because the attached object is getting streamed before the base object. That could be caused by a recent change, actually. Try setting the priority of the base object lower than all surrounding objects (-1 for example).

Tagic commented 7 years ago

I'm using 2.9.1 version of Streamer, and R19 of YSF. First I set base object priority to -1 like you said and it doesn't work then i try to set attach object priority to 1 and it still don't work. I Don't know if this is Streamer or YSF bug but it is bug :/ and it bothers me. And one more thing now when i change priority I see only the base object but i create like 12 other objects and attach them when i open F5 menu ObjectSlotUsed show me that there is 13 object created (1 base and 12 attach) but there is no attach objects visible (even in virtualworld or interior)

ghost commented 7 years ago

Try it with older ysf, if it works with r18 then its problem.in ysf

Tagic commented 7 years ago

@kurta999 With r18 is just like r19. It work but sometimes, when i call command it create base object and attach objects, but sometimes it create only the base object without attachments but on ObjectSlotUsed they are created. When attach objects are created with success and when I go far away and go back there are no attach objects visible but on ObjectSlotUsed they are. :/

Tagic commented 7 years ago

Any fixes? @kurta999 @samp-incognito

samp-incognito commented 7 years ago

If the objects are being created but just aren't visible, then it's likely either a YSF or an SA-MP problem. Have you tried testing it with an older streamer plugin version?

ghost commented 7 years ago

Gonna test it today

ghost commented 7 years ago

The problem looks like in the streamer.

AMX_DECLARE_NATIVE(Natives::AttachPlayerObjectToObject) { logprintf("attach"); bllbablablal }

This message doesn't appear when objects are restreamed

samp-incognito commented 7 years ago

That's odd. I'm not sure why that native would stop working.

Tagic commented 7 years ago

I really need this function, can you fix this? Next update?

DignitySAMP commented 7 years ago

Hi,

I'm having this issue as well. I use it for my horse mounting / dismounting system, and it seems that the objects that recieve the same ID as the attached object also get removed - regardless of being attached or not.

They also get removed mid-attachment. I don't know what exactly triggers it on my end though so I can't give more info on that.

Maybe @kurta999 can create a function i.e. RemoveAttachedObject to properly clean the object up after it's being detached. Right now I have to destroy and recreate it.

I tried setting priorities to the objects as an attempt to patch this but to no avail - it just made the random removing worse.

I really hope there's a fix coming out for this soon. Thanks

roun512 commented 7 years ago

Well, this is kind of the same for me. If I spawn 2 dynamic objects with a code like this:

Box = CreateDynamicObjectEx(2975, x, y, z - 15.0, 0.0, 0.0, 0.0, STREAMER_OBJECT_SD, 800.0); Parachute = CreateDynamicObjectEx(18849, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, STREAMER_OBJECT_SD, 800.0);

and then I attach the parachute to the box with:

AttachDynamicObjectToObject(Parachute, Box, 0.0, -0.05, 7.5, 0.0, 0.0, 0.0, 1);

If I am in the streamed area I'll see both the parachute and the box objects, if I am not, I'll see the box where it is supposed to be while the parachute will be on 0.0 0.0 0.0.

Am I misusing the function parameters in any way or? Thanks.

Fleynaro commented 7 years ago

same problem. It appears since 2.9.0. Please, try founding a solution

IstuntmanI commented 7 years ago

I did some research (of this and #193). This may be my mistake. I did some cleanup inside the plugin related to IDs definitions (they were pretty messed up) and I think that I messed up few checks. Here are the lines that I think that should be changed:

  1. https://github.com/samp-incognito/samp-streamer-plugin/blob/b5b5257b12c0669b78e8c72528a39fcbf01aea05/src/natives/objects.cpp#L393
  2. https://github.com/samp-incognito/samp-streamer-plugin/blob/b5b5257b12c0669b78e8c72528a39fcbf01aea05/src/streamer.cpp#L1155
  3. https://github.com/samp-incognito/samp-streamer-plugin/blob/b5b5257b12c0669b78e8c72528a39fcbf01aea05/src/streamer.cpp#L1711
  4. https://github.com/samp-incognito/samp-streamer-plugin/blob/b5b5257b12c0669b78e8c72528a39fcbf01aea05/src/manipulation/int.cpp#L722
  5. https://github.com/samp-incognito/samp-streamer-plugin/blob/b5b5257b12c0669b78e8c72528a39fcbf01aea05/src/manipulation/int.cpp#L58

Shouldn't INVALID_STREAMER_ID be INVALID_OBJECT_ID in all these lines ? Not sure if these are the problems related to this issue, as those are related only to valid ID checking, the OP's code should work with both INVALID_STREAMER_ID and INVALID_OBJECT_ID.

@samp-incognito, can you take a quick look at this, if this is indeed the problem ?

samp-incognito commented 7 years ago

Yes, those should all be INVALID_OBJECT_ID. I noticed that earlier as well. #193 is also affected by this.

Fleynaro commented 7 years ago

when a fix?

Such problem was also in 2.8.2, but if the attached object`s position(global) was defined as 0,0,0(I even made video https://www.youtube.com/watch?v=a48wswSNrwI). If the pos are some coords(near the main object), I have not this issue

In 2.9.0 and 2.9.1 the problem exists any way. Try to compare the code of old and current version to found a changing that causes this problem

Fleynaro commented 7 years ago

It`s strange, but when I set the PRIORITY(1 to the base object, not -1), everything works well. It means that need to set the priority of the base object higher?

Code: Streamer_SetIntData(STREAMER_TYPE_OBJECT, objectid, E_STREAMER_PRIORITY, 1);

@Tagic, @mmimix, @samp-incognito?

DignitySAMP commented 7 years ago

@Fleynaro This is not a suitable solution. I tried this as well, but from what I've noticed is that adding priorities will result in other priority objects, or even unrelated objects getting unstreamed (or removed in this case) - especially under load.

samp-incognito commented 7 years ago

Should be fixed now with 33ab0b1.

samp-incognito commented 7 years ago

Yes, those should all be INVALID_OBJECT_ID.

Sorry, I realized just now that this is backwards. These should actually all be INVALID_STREAMER_ID. We're attaching dynamic objects, not player objects, so INVALID_OBJECT_ID is still a valid ID. The problem before was that this was inconsistent in the code.

rt-2 commented 7 years ago

Technicly INVALID_STREAMER_ID should be called INVALID_DYNAMICOBJECT_ID or INVALID_DYNOBJECT_ID to avoid this confusion.

IstuntmanI commented 7 years ago

INVALID_STREAMER_ID is also used for other streamed things, such as dynamic areas, dynamic pickups and so on.

I hope that your commit, Incognito, fixes it. I am really sure that when I tested that commit it was fixed and when I used the old code it wasn't working again, probably something weird happened internally (I can't explain what).

Maybe @Tagic or @roun512 or @Fleynaro want to test this again, with the latest commit ? Here is it compiled, both Release and Debug versions, with the .pdb file for Windows Debug: https://mega.nz/#!ahpCSaiB!kj4yc2nRlOKODIZ2QsJXzFWiiXTe-3TqrVMWxpFTwcI

By the way, @samp-incognito, I couldn't compile it on Windows, some boost files are missing, at least this one:

...\samp-streamer-plugin\include\boost\bimap\tags\support\tag_of.hpp(22): fatal error C1083: Cannot open include file: 'boost/bimap/detail/debug/static_error.hpp': No such file or directory

solved it by downloading Boost v1.61 again.

samp-incognito commented 7 years ago

I am really sure that when I tested that commit it was fixed and when I used the old code it wasn't working again, probably something weird happened internally (I can't explain what).

Your code was fine, for most part. In the (unlikely) event that someone someone specified an object ID of 65535, though, it wouldn't have worked.

I couldn't compile it on Windows, some boost files are missing

Thanks, it looks like .gitignore skipped those. I'll upload them later.

Tagic commented 7 years ago

It's working for now.. we'll see

WestSide56 commented 5 years ago

not fixed. streamer 2.9.4 YSF R20-RC4 (03DL) attached object attaching to other objects in stream.

mikecnr commented 2 years ago

Also having the same issue. Only working fix I found was to ensure the parent object is streamed in before the child object. Not an ideal solution however.

Surely if an object is attached to another object, the streaming should be handled differently, i.e. when the main object streams in, find any objects attached to it, stream those in, ensure they are attached? Surely they shouldn't be treated as 2 separate objects in terms of streaming.

EDIT: Also, it doesn't happen always.

Here's a bare script I made to try and test some things:

#include <a_samp>
#include <streamer>
#include <zcmd>
#include <YSF>

main() {}

public OnGameModeInit()
{
    AddPlayerClass(0, 3, 3, 3, 0, 0, 0, 0, 0, 0, 0);

    new objectid = CreateDynamicObject(1238, 0, 0, 3, 0, 0, 0);
    new objectid2 = CreateDynamicObject(1238, 0, 0, 3, 0, 0, 0);
    AttachDynamicObjectToObject(objectid2, objectid, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0);

    return 1;
}

CMD:teleaway()
{
    SetPlayerPos(playerid, 3000, 3000, 0);

    return 1;
}

CMD:teleback()
{
    SetPlayerPos(playerid, 6, 6, 6);

    return 1;
}

I could not replicate the issue here. I think it only occurs if you have a vast number of streamed objects.

EDIT2: The issue also seems less likely to happen (although I'm not placing my confidence in it) if you create the child object at the same coordinates as the parent object, rather than at 0.0, 0.0, 0.0.