|
|
Line 1: |
Line 1: |
| I'd really like assistance with this if anyone can do any implementation of this or any fixes to the bullet simulator... implementation includes making the gun shoot them out, making the bullets hurt, and making clientside effects... I have a feeling that other mods WILL want to use timed bullets, and this code will do the trick... I just need help (or plenty of time) getting it finished first and then it will be available to everyone!—'''[[User:Ts2do|ts2do]]''' <sup>([[User talk:Ts2do|Talk]] | [mailto:tsdodo@gmail.com @])</sup> 23:06, 20 Nov 2005 (PST) | | I'd really like assistance with this if anyone can do any implementation of this or any fixes to the bullet simulator... implementation includes making the gun shoot them out, making the bullets hurt, and making clientside effects... I have a feeling that other mods WILL want to use timed bullets, and this code will do the trick... I just need help (or plenty of time) getting it finished first and then it will be available to everyone!—'''[[User:Ts2do|ts2do]]''' <sup>([[User talk:Ts2do|Talk]] | [mailto:tsdodo@gmail.com @])</sup> 23:06, 20 Nov 2005 (PST) |
| ::Yes ts2do (you went away before i came back), the myth was busted, best to contact Wrayith at Nightfall mod for more info. He was interested, and was implementing something like this with the quake 2 code, and was going to port it to hl2 latter. MSN wraiyth@gmail.com --[[User:Amckern|Amckern]] 01:07, 21 Nov 2005 (PST) | | ::Yes ts2do (you went away before i came back), the myth was busted, best to contact Wrayith at Nightfall mod for more info. He was interested, and was implementing something like this with the quake 2 code, and was going to port it to hl2 latter. MSN wraiyth@gmail.com --[[User:Amckern|Amckern]] 01:07, 21 Nov 2005 (PST) |
| Does anyone know what it means if I'm getting this sort of error on the client:
| |
| client.dll!CUtlMemory<CSimulatedBullet *>::Base() Line 252 + 0x3
| |
| client.dll!CUtlVector<CSimulatedBullet *,CUtlMemory<CSimulatedBullet *> >::Base() Line 54 + 0x14
| |
| client.dll!CUtlVector<CSimulatedBullet *,CUtlMemory<CSimulatedBullet *> >::AddToTail(CSimulatedBullet * const & src=0x044fc440) Line 403 + 0x8
| |
| It seems to not like me adding an item to the utlvector on the client but it's fine with it on the server
| |
| —'''[[User:Ts2do|ts2do]]''' <sup>([[User talk:Ts2do|Talk]] | [mailto:tsdodo@gmail.com @])</sup> 10:52, 23 Nov 2005 (PST)
| |
|
| |
|
| :How are you calling AddBullet? Is the parameter on the heap or stack? By the way, since CSimulatedBullet has dynamically-allocated members, you need a non-default copy constructor and copy assignment operator; otherwise you'll have leaks and possibly crashes if a CSimulatedBullet is ever copied. If it's never going to be copied, make the copy constructor and copy assignment operator private and undefined. —'''[[User:Maven|Maven]]''' <sup>([[User talk:Maven|talk]])</sup> 11:31, 23 Nov 2005 (PST)
| | [snip] |
| | |
| I've tried a copy constructor b4...
| |
| but what do you mean dynamically allocated...what objects? the pointers?
| |
| <pre> CSimulatedBullet *pBullet = new CSimulatedBullet(pAttacker, info.m_pAdditionalIgnoreEnt,
| |
| info.m_iAmmoType, info.m_nFlags, vecDir, vecSrc, nDamageType
| |
| #ifndef CLIENT_DLL
| |
| , this, info.m_iDamage, 0.0f
| |
| #endif
| |
| );
| |
| BulletManager()->AddBullet(pBullet);</pre>
| |
| Also...I neglected to use a linked list because it would cost more allocation...—'''[[User:Ts2do|ts2do]]''' <sup>([[User talk:Ts2do|Talk]] | [mailto:tsdodo@gmail.com @])</sup> 11:43, 23 Nov 2005 (PST)
| |
| | |
| why const ints instead of defines?—'''[[User:Ts2do|ts2do]]''' <sup>([[User talk:Ts2do|Talk]] | [mailto:tsdodo@gmail.com @])</sup> 13:43, 23 Nov 2005 (PST)
| |
| | |
| :The dynamic allocation is at the <pre>m_pIgnoreList = new CTraceFilterSimpleList(COLLISION_GROUP_NONE);</pre> and <pre>m_pTwoEnts = new CTraceFilterSkipTwoEntities(pAttacker,pAdditionalIgnoreEnt,COLLISION_GROUP_NONE);</pre> lines—the CTraceFilterSimpleList and CTraceFilterSkipTwoEntities objects are dynamically allocated. You <code>delete</code>d them in the dtor, which is good, but if a CSimulatedBullet were copied both the original and the copy would point to the same CTraceFilterSimpleList and CTraceFilterSkipTwoEntities objects. When either CSimulatedBullet gets deleted, the other one is now pointing at CTraceFilterSimpleList and CTraceFilterSkipTwoEntities objects that have been deleted. As a rule of thumb, if you have to make a custom dtor you also need to make a custom copy constructor and assignment operator.
| |
| | |
| :For the <code>const int</code>s instead of <code>#define</code>s: macros were fine in C but it's good practice to avoid them in C++. There are some reasons for this, but they're not particularly relevant. The SDK has them strewn everywhere anyway, so it's probably not going to hurt anything to add a few more, though.
| |
| | |
| :For the sample you gave, do you use <code>pBullet</code> anywhere else before it goes out of scope? —'''[[User:Maven|Maven]]''' <sup>([[User talk:Maven|talk]])</sup> 13:59, 23 Nov 2005 (PST)
| |
| | |
| :If, with the private copy ctor and operator=, you get compiler errors complaining about them being private, then that means you need to either implement them or avoid the copy. Let me know if that's the case, please. —'''[[User:Maven|Maven]]''' <sup>([[User talk:Maven|talk]])</sup> 14:01, 23 Nov 2005 (PST)
| |
| I don't use pBullet anywhere else...but I had a feeling that the pointers were giving errors...why would they if I was just calling AddToTail...no code was run thru where a null pointer would be a problem....—'''[[User:Ts2do|ts2do]]''' <sup>([[User talk:Ts2do|Talk]] | [mailto:tsdodo@gmail.com @])</sup> 14:10, 23 Nov 2005 (PST)
| |
| | |
| Still looking. By the way, <code>m_pBullets</code> shouldn't have a <code>p</code> in its name since it's not a pointer—<code>m_bullets</code> or <code>m_Bullets</code> would be correct. It won't hurt the code, but it confuses people who read it. Ditto <code>m_pCompensationConsiderations</code>. —'''[[User:Maven|Maven]]''' <sup>([[User talk:Maven|talk]])</sup> 14:19, 23 Nov 2005 (PST)
| |
| | |
| I still don't understand why this is working perfectly on the serverdll and not on the clientdll...I've made said changes and still get the same results—'''[[User:Ts2do|ts2do]]''' <sup>([[User talk:Ts2do|Talk]] | [mailto:tsdodo@gmail.com @])</sup> 14:48, 23 Nov 2005 (PST)
| |
| | |
| :<code>CUtlVector</code> directly invokes ctors and dtors on its elements. Notably, <code>AddToTail</code> (indirectly) calls the copy constructor. However, since you're storing ''pointers'' in the CUtlVector, the <code>CSimulatedBullet*</code> pointer is being copied rather than the <code>CSimulatedBullet</code> object. I'm not completely sure (I'd want to test it first), but that ''should'' be OK (ie, no crashes) except for creating massive memory leaks. I see that Valve stores pointers in a CUtlVector elsewhere, so perhaps I'm mistaken. I suppose you could try refactoring things so that you have <code>CUtlVector<CSimulatedBullet> m_bullets;</code> instead of <code>CUtlVector<CSimulatedBullet*> m_pBullets;</code>, but I'm not sure that that would solve things, and you'd definately need a copy ctor then. An easier step would be to start sprinkling <code>Assert</code>s everywhere, especially around AddToTail and Remove.
| |
| | |
| :I'll be away for a few days, and perhaps I'll look at it some more then. —'''[[User:Maven|Maven]]''' <sup>([[User talk:Maven|talk]])</sup> 14:56, 23 Nov 2005 (PST)
| |
| | |
| well...I really can't assert anything because it's the addtotail thing that's giving me problems and nothing else...though I did try making it <CSimulatedBullet> and <SimulatedBullet_t>....all failed...a linked list works, but I don't believe it would be the best way because it allocates memory every time one is made...correct?—'''[[User:Ts2do|ts2do]]''' <sup>([[User talk:Ts2do|Talk]] | [mailto:tsdodo@gmail.com @])</sup> 16:22, 23 Nov 2005 (PST)
| |
| | |
| :Plans have changed; I've not left quite yet.
| |
| | |
| :Ok, I've been looking more at the code, and <code>CBulletManager::Think</code> has a problem. If during the <code>for</code> loop a bullet removes itself, that will cause the contents of the vector to be shifted (a slow, O(n), operation) which in turn will cause the following bullet to not be processed until the next Think. (Unless removals happen almost always at the tail of the vector and/or the vector is always very small, a linked list would probably be more time-efficient than a vector.) As a general rule, it's not a good idea to modify a collection (<code>m_pBullets</code>) while iterating over it (the <code>for</code> loop in <code>Think</code>). That's true even of a linked list, by the way. I don't see that this would cause your problem, though.
| |
| | |
| :I can't see ''any'' way that <code>CUtlMemory<T>::Base()</code> could possibly throw an error. It's just a member accessor, and its object should already be constructed. Unless [http://hl2doxygen.sniperumm.co.uk/d4/d41/utlmemory_8h-source.html utlmemory.h] has changed, which is doubtful. Perhaps if the vector or its allocator were corrupted, then the error might be possible (as an access violation). It's a pity that the error message doesn't say what's ''wrong''.
| |
| | |
| :Are you willing to post the complete code that uses this code? Having live code would make debugging easier. Also, does the error happen on your ''first'' <code>AddBullet</code>? Second? Does it happen every time? Does it happen after the computer's been restarted? —'''[[User:Maven|Maven]]''' <sup>([[User talk:Maven|talk]])</sup> 20:50, 23 Nov 2005 (PST)
| |
| | |
| Linked list...I'm not sure but I think the last time I tried that, I got no errors...I'll try it again then...
| |
| | |
| the crash has been happening for 2 days first bullet multiplayer....what code do you want? baseentity_shared?—'''[[User:Ts2do|ts2do]]''' <sup>([[User talk:Ts2do|Talk]] | [mailto:tsdodo@gmail.com @])</sup> 21:33, 23 Nov 2005 (PST)
| |
| | |
| Using a linked list:
| |
| <pre> client.dll!CUtlLinkedList<C_SimulatedBullet *,int>::AllocInternal(bool multilist=false) Line 334 + 0x8 C++
| |
| client.dll!CUtlLinkedList<C_SimulatedBullet *,int>::InsertBefore(int before=-1, C_SimulatedBullet * const & src=0x04d16390) Line 447 + 0xa C++
| |
| client.dll!CUtlLinkedList<C_SimulatedBullet *,int>::AddToTail(C_SimulatedBullet * const & src=0x04d16390) Line 483 C++
| |
| client.dll!C_BulletManager::AddBullet(C_SimulatedBullet * pBullet=0x04d16390) Line 332 + 0x12 C++
| |
| </pre>
| |
| —'''[[User:Ts2do|ts2do]]''' <sup>([[User talk:Ts2do|Talk]] | [mailto:tsdodo@gmail.com @])</sup> 15:19, 25 Nov 2005 (PST)
| |
| | |
| How's it coming? —'''[[User:Maven|Maven]]''' <sup>([[User talk:Maven|talk]])</sup> 20:49, 26 Nov 2005 (PST)
| |
| | |
| well I got it to be consistent...now it crashes in singleplayer too coz it sends the bullet to the client...just gotta know why it doesn't like it clientside tho...ask valve plz lol...it's a very large article now, don't you agree? only major thing missing here is actually getting the gun to shoot it—'''[[User:Ts2do|ts2do]]''' <sup>([[User talk:Ts2do|Talk]] | [mailto:tsdodo@gmail.com @])</sup> 20:55, 26 Nov 2005 (PST)
| |
| | |
| :Well, once you've posted all the code needed to run this, then it will be easier for other people to help. I'm glad you have a second error that I can examine, though, because now I can try to find the common factor(s). —'''[[User:Maven|Maven]]''' <sup>([[User talk:Maven|talk]])</sup> 14:41, 27 Nov 2005 (PST)
| |
| | |
| there..I posted a hack to make ti work for now...tell me if you get any problems compiling [[Simulated_Bullets#baseentity_shared.cpp|<nowiki>[1]</nowiki>]]—'''[[User:Ts2do|ts2do]]''' <sup>([[User talk:Ts2do|Talk]] | [mailto:tsdodo@gmail.com @])</sup> 14:51, 27 Nov 2005 (PST)
| |
| | |
| Are we using / or \ for files?—'''[[User:Ts2do|ts2do]]''' <sup>([[User talk:Ts2do|Talk]] | [mailto:tsdodo@gmail.com @])</sup> 17:17, 27 Nov 2005 (PST)
| |
| | |
| Whichever. I'll try to be consistent.—'''[[User:Maven|Maven]]''' <sup>([[User talk:Maven|talk]])</sup> 17:36, 27 Nov 2005 (PST)
| |
| | |
| OK, I've duplicated the problem, with the same call stack. —'''[[User:Maven|Maven]]''' <sup>([[User talk:Maven|talk]])</sup> 17:37, 27 Nov 2005 (PST)
| |
| | |
| is that good, bad, or good and bad? also...it'll work fine in singleplayer if you comment out the "Bullet" message being sent...and it'll work in multiplayer if you do that and cl_predict 0—'''[[User:Ts2do|ts2do]]''' <sup>([[User talk:Ts2do|Talk]] | [mailto:tsdodo@gmail.com @])</sup> 17:40, 27 Nov 2005 (PST)
| |
| | |
| :It's good. It means I can properly debug it now. —'''[[User:Maven|Maven]]''' <sup>([[User talk:Maven|talk]])</sup> 17:45, 27 Nov 2005 (PST)
| |
| | |
| I see a lot of <code>CXX0030</code> errors when examining values. That probably indicates that <code>this</code> points to an invalid object—eg, it was obtained from an out-of-bound array index or has been destroyed. Still looking. —'''[[User:Maven|Maven]]''' <sup>([[User talk:Maven|talk]])</sup> 18:06, 27 Nov 2005 (PST)
| |
| | |
| I'm getting a different error currently, caused by a NULL <code>pAdditionalIgnoreEnt</code> parameter to the with-args version of <code>CSimulatedBullet::CSimulatedBullet</code>. You have lines:
| |
| <pre>
| |
| if (pAdditionalIgnoreEnt!=NULL)
| |
| m_pIgnoreList->AddEntityToIgnore(pAdditionalIgnoreEnt);
| |
| </pre>
| |
| but never assign <code>pAdditionalIgnoreEnt</code> a non-NULL value. Later you call <code><nowiki>pAdditionalIgnoreEnt->entindex()</nowiki></code>. —'''[[User:Maven|Maven]]''' <sup>([[User talk:Maven|talk]])</sup> 18:23, 27 Nov 2005 (PST)
| |
| | |
| it's done got fixed—'''[[User:Ts2do|ts2do]]''' <sup>([[User talk:Ts2do|Talk]] | [mailto:tsdodo@gmail.com @])</sup> 18:30, 27 Nov 2005 (PST)
| |
| | |
| Found the problem: <code>g_pBulletManager</code> is not being initialized in the client.
| |
| | |
| Change <code>CBaseEntity::FireBullets</code> to use
| |
| <pre>
| |
| // Add the bullet to the bullet manager
| |
| #ifdef CLIENT_DLL
| |
| C_BulletManager* pBMan = BulletManager();
| |
| Assert( pBMan );
| |
| pBMan->AddBullet(pBullet);
| |
| #else
| |
| CBulletManager* pBMan = BulletManager();
| |
| Assert( pBMan );
| |
| pBMan->AddBullet(pBullet, info.m_flLatency);
| |
| #endif
| |
| </pre>
| |
| and the first shot fails that first assertion. —'''[[User:Maven|Maven]]''' <sup>([[User talk:Maven|talk]])</sup> 18:55, 27 Nov 2005 (PST)
| |
| | |
| Well! that's what happens with shared code! for me at least...—'''[[User:Ts2do|ts2do]]''' <sup>([[User talk:Ts2do|Talk]] | [mailto:tsdodo@gmail.com @])</sup> 19:08, 27 Nov 2005 (PST)
| |
| | |
| I don't have a fix, offhand. You already have <code><nowiki>C_BulletManager *g_pBulletManager = (C_BulletManager *)CreateEntityByName("bullet_manager");</nowiki></code>. Maybe that needs to be run later (the data CreateEntityByName uses might not have been constructed yet). —'''[[User:Maven|Maven]]''' <sup>([[User talk:Maven|talk]])</sup> 19:15, 27 Nov 2005 (PST)
| |
|
| |
|
| I was thinking that too...I put a constructor and deconstructor in the manager that prints warnings saying created and destroyed...I'll see if it's destroying it too soon then—'''[[User:Ts2do|ts2do]]''' <sup>([[User talk:Ts2do|Talk]] | [mailto:tsdodo@gmail.com @])</sup> 19:19, 27 Nov 2005 (PST) | | I was thinking that too...I put a constructor and deconstructor in the manager that prints warnings saying created and destroyed...I'll see if it's destroying it too soon then—'''[[User:Ts2do|ts2do]]''' <sup>([[User talk:Ts2do|Talk]] | [mailto:tsdodo@gmail.com @])</sup> 19:19, 27 Nov 2005 (PST) |
I'd really like assistance with this if anyone can do any implementation of this or any fixes to the bullet simulator... implementation includes making the gun shoot them out, making the bullets hurt, and making clientside effects... I have a feeling that other mods WILL want to use timed bullets, and this code will do the trick... I just need help (or plenty of time) getting it finished first and then it will be available to everyone!—ts2do (Talk | @) 23:06, 20 Nov 2005 (PST)
- Yes ts2do (you went away before i came back), the myth was busted, best to contact Wrayith at Nightfall mod for more info. He was interested, and was implementing something like this with the quake 2 code, and was going to port it to hl2 latter. MSN wraiyth@gmail.com --Amckern 01:07, 21 Nov 2005 (PST)
[snip]
I was thinking that too...I put a constructor and deconstructor in the manager that prints warnings saying created and destroyed...I'll see if it's destroying it too soon then—ts2do (Talk | @) 19:19, 27 Nov 2005 (PST)
Ok...I made it so it creates the manager when it does the clientshared thing...haven't tried restarting the server and seeing if it's still intact yet tho...what I did b4 was made it when the clientdll initialized WHICH ISN"T GOODZ!—ts2do (Talk | @) 19:32, 27 Nov 2005 (PST)
Now it fails Assert( !"CreateNoSpawn: only works for CBaseEntities" );
.
server.dll!CBaseEntity::CreateNoSpawn(const char * szName=0x22a8b92c, const Vector & vecOrigin={...}, const QAngle & vecAngles={...}, CBaseEntity * pOwner=0x00000000) Line 2451 + 0x69 C++
server.dll!CBaseEntity::Create(const char * szName=0x22a8b92c, const Vector & vecOrigin={...}, const QAngle & vecAngles={...}, CBaseEntity * pOwner=0x00000000) Line 2436 + 0x15 C++
server.dll!CGameRules::CreateStandardEntities() Line 552 + 0x16 C++
server.dll!CHL2MPRules::CreateStandardEntities() Line 183 C++
server.dll!CWorld::Precache() Line 605 C++
server.dll!CWorld::Spawn() Line 513 C++
server.dll!DispatchSpawn(CBaseEntity * pEntity=0x0bd13400) Line 1727 C++
server.dll!MapEntity_ParseAllEntities(const char * pMapData=0x118cf1d8, IMapEntityFilter * pFilter=0x00000000, bool bActivateEntities=false) Line 329 + 0xc C++
server.dll!CServerGameDLL::LevelInit_ParseAllEntities(const char * pMapEntities=0x118cf040) Line 27 + 0xd C++
server.dll!CServerGameDLL::LevelInit(const char * pMapName=0x0de1fb10, const char * pMapEntities=0x118cf040, const char * pOldLevel=0x00000000, const char * pLandmarkName=0x00000000, bool loadGame=false, bool background=false) Line 700 C++
szName "bullet_manager" const char *
vecOrigin {x=0.00000000 y=0.00000000 z=0.00000000 } const Vector &
vecAngles {x=0.00000000 y=0.00000000 z=0.00000000 } const QAngle &
pOwner 0x00000000 CBaseEntity *
—Maven (talk) 20:10, 27 Nov 2005 (PST)