PB crashes after typing "meta unload podbot"
Why?: because when metamod unloads your module, attempts of engine to reference any string in the podbot will produce a segfault. For now metamod protects only console variables and commands from it.
Solution: For the engine functions such as "PRECACHE_*", "SET_MODEL" and "MAKE_STRING" transfer of the string to argument of this functions should look like this: Code:
282: PRECACHE_SOUND (STRING (ALLOC_STRING ("weapons/xbow_hit1.wav"))); P.S. Sorry for bad english. |
Re: PB crashes after typing "meta unload podbot"
If I have already allocated a memory area for precached model, what should I use in SET_MODEL function then? I don't think I need to allocate the memory the second time for the model name... I believe I should store somewhere the pointer to that area of precached model, then I should use this pointer somehow in SET_MODEL function. Can You describe it more clearly? My skill of C++ coding seems to be still really poor comparing to skill of other developers at this forum... :(
[EDIT] After compilation I'm getting such errors: 282: PRECACHE_SOUND (STRING (ALLOC_STRING ("weapons/xbow_hit1.wav"))); // waypoint add 1>.\dll.cpp(282) : error C2664: 'int (char *)' : cannot convert parameter 1 from 'const char *' to 'char *' Can You help with this? |
Re: PB crashes after typing "meta unload podbot"
Quote:
PRECACHE_SOUND (STRING (ALLOC_STRING ((char *)"weapons/xbow_hit1.wav"))) or (more C++'ish): PRECACHE_SOUND (STRING (ALLOC_STRING (reinterpret_cast<char *>("weapons/xbow_hit1.wav")))) |
Re: PB crashes after typing "meta unload podbot"
Quote:
Code:
#define STRING(offset) (const char *)(gpGlobals->pStringBase + (int)offset) Code:
PRECACHE_SOUND ((char *)STRING (ALLOC_STRING ("weapons/xbow_hit1.wav"))); // C style Quote:
Code:
// From Q1 sources, but it's still actual.... |
Re: PB crashes after typing "meta unload podbot"
I didn't check the macro ALLOC_STRING but in this way of allocation I think that we may end up with memory leak? Will the engine free the string?
|
Re: PB crashes after typing "meta unload podbot"
The engine will free this memory in function 'Sys_ShutdownMemory', so leaks won't be
|
Re: PB crashes after typing "meta unload podbot"
> You are wrong here as it is STRING macro returns the constant pointer.
sorry... I did not checked the actual code before posting :( |
Re: PB crashes after typing "meta unload podbot"
Quote:
dll.cpp 286: m_spriteTexture = PRECACHE_MODEL ("sprites/lgtning.spr"); then m_spriteTexture (which - I believe - it's a pointer to the model name string) is used i.e. in util.cpp: 1755: WRITE_SHORT (m_spriteTexture); So - the question was: a) should SET_MODEL function should be used the same way - with stored pointer: now in dll.cpp: 291: SET_MODEL (pent, "models/player/urban/urban.mdl"); but maybe - if I want to use this model name couple of times in code - it should be: m_model_urban = PRECACHE_MODEL(const_cast<char *>(STRING (ALLOC_STRING ("models/player/urban/urban.mdl")))); SET_MODEL (pent, m_model_urban); b) if the model in example a) doesn't need to be precached, because it was already precached somewhere, how the function SET_MODEL should look like? c) if I want to use the model name once to set - should the example look like: SET_MODEL(const_cast<char *>(STRING (ALLOC_STRING ("models/player/urban/urban.mdl"))))? For me it's more clear if I can see 2 lines of working examples than somebody writes me 1 page of the theory which I cannot get if I cannot see the result how does it work like. I mean please write 1 example for each function types You were refering to (in the first post) they need to be changed. I mean 1 example how it should look like each SET_MODEL function, 1 example how it should look like MAKE_STRING etc - with eventually something which needs to be added before (like storing a pointer or something or precaching a string and so on). I know this is a pre-school of C++, but as I said - I know how to make the logic to make some working (and even really complicated) code, but I have lack of C++ basic knowledge, so anything new for me makes me troubles if I don't see the working example. Thanks to everybody for helping and understanding. [EDIT] Finally I did all those ALLOC_STRING for proposed SET_MODEL, PRECACHE_* and MAKE_STRING functions and meta unload finally doesn't crash the server, but there are additionally questions: a) how to use the pointer to precached model mechgibs in dll.cpp - end of ServerActivate function: 1824: PRECACHE_MODEL((char *)STRING (ALLOC_STRING ("models/mechgibs.mdl"))) later in the code in StartFrame function: 1968: SET_MODEL (pClient->pIllumEnt, (char *)STRING (ALLOC_STRING ("models/mechgibs.mdl"))); I mean - if that second ALLOC_STRING leads or doesn't lead to memory leak because of allocating the memory for the same string couple of times - I can feel here some problem. b) after succesful unloading podbot_mm.dll all slots used by bots still are in use (also You can see not moving bots on the server - like clients away from the keyboard - how to remove them automatically while using meta unload command? [/EDIT] |
Re: PB crashes after typing "meta unload podbot"
Quote:
See example from HL engine: (It was necessary at once and to lay out, I simply was too lazy) Code:
int PF_precache_model_I (const char *const modelName) Quote:
Here is complete list of things that you should change in your code: Code:
int Spawn (edict_t *pent) Quote:
But it can be bypassed easily, in such a way: (just a example, you can write something more pretty) Code:
enum String_t Quote:
Code:
PbCmdParser (NULL, g_rgpszPbCmds[PBCMD_REMOVEBOTS], NULL, NULL, NULL, NULL, NULL); Code:
C_DLLEXPORT int Meta_Detach (PLUG_LOADTIME now, PL_UNLOAD_REASON reason) |
Re: PB crashes after typing "meta unload podbot"
OK. Thanks for the explanation. :)
I would like to go forward that change about checking by the bots if there is a darkness or not (to prevent use an extra entity with mechigbs.mdl). But until now I didn't get what I need to add in the code, if I need to update my HLSDK for some functions and so on. I'll try to read that topic second time, then I'll probably ask about more explanation. [EDIT] Why exactly in ServerActivate - there is no need to allocate the memory for the string? 1824: PRECACHE_MODEL("models/mechgibs.mdl"); Or You just maybe have forgotten to write it so: 1824: PRECACHE_MODEL(const_cast <char *> ALLOC_STRING("models/mechgibs.mdl")); [/EDIT] |
All times are GMT +2. The time now is 04:25. |
Powered by vBulletin® Version 3.8.2
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.