.:: Bots United ::.  
filebase forums discord server github wiki web
cubebot epodbot fritzbot gravebot grogbot hpbbot ivpbot jkbotti joebot
meanmod podbotmm racc rcbot realbot sandbot shrikebot soulfathermaps yapb

Go Back   .:: Bots United ::. > Developer's Farm > General Bot Coding
General Bot Coding See what a pain it is to get those little mechs shooting around

Reply
 
Thread Tools
Plugin crash...
Old
  (#1)
He@dShot
Member
 
He@dShot's Avatar
 
Status: Offline
Posts: 40
Join Date: Mar 2008
Location: Romania, Craiova
Default Plugin crash... - 20-05-2008

Why does my plugin crashes when I use either globalvars_t->time, or globalvars_t->maxClients ? ? ?

I made a pointer to globalvars_t in my header file like so:

float think_timer;
globalvars_t *globals;

when I use it in StartFrame() in my metamod plugin like so:

if (timer < globals->time)
{
// do something
}

IT CRASHES: what is wrong ???
  
Reply With Quote
Re: Plugin crash...
Old
  (#2)
The Storm
Council Member / E[POD]bot developer
 
The Storm's Avatar
 
Status: Offline
Posts: 1,618
Join Date: Jul 2004
Location: Bulgaria
Default Re: Plugin crash... - 20-05-2008

From the code you showed it seems that you are just using invalid pointer, it's normal to crash. You must give it proper value in h_export.cpp. Here is code sample from one "stub" metamod plugin:
Code:
//! Holds engine functionality callbacks
enginefuncs_t g_engfuncs;
globalvars_t  *gpGlobals;

// Receive engine function table from engine.
// This appears to be the _first_ DLL routine called by the engine, so we
// do some setup operations here.
void WINAPI GiveFnptrsToDll( enginefuncs_t* pengfuncsFromEngine, globalvars_t *pGlobals )
{
	memcpy(&g_engfuncs, pengfuncsFromEngine, sizeof(enginefuncs_t));
	gpGlobals = pGlobals;
}
Now you can do extern the variable in any header or source file to use it(hint don't declare the pointer in to the header files, just extern it, it must be declared only once in a .cpp file and after that only "externed").

Sinse I see that you don't have much expirience in C++ I will give you little example that is explained well, lets say that you already declared and initalized the gpGlobals pointer in h_export.cpp and after that you want to use it in other source file like for example "my_plugin_source.cpp". You must put this
Code:
extern globalvars_t *gpGlobals;
after the include line or if you have header "my_plugin_source.h" that is included by "my_plugin_source.cpp" better put it there. Anyway I recommend other better practice for such global variables/pointers. Make two files like "globals.cpp" and "globals.h", declare the variable/pointer in to the "globals.cpp" and do the extern in "globals.h", then include "globals.h" in any source file that you want to use the variables/pointers that you declared there, in h_export.cpp leave just the function GiveFnptrsToDll() to give your global pointer proper value.

Here is code examples:

globals.h file
Code:
#include <extdll.h>

#include <h_export.h>

extern enginefuncs_t g_engfuncs;
extern globalvars_t *gpGlobals;
globals.cpp file
Code:
#include "globals.h"


//! Holds engine functionality callbacks
enginefuncs_t g_engfuncs;
globalvars_t *gpGlobals;
h_export.cpp file

Code:
#include "globals.h"

// Receive engine function table from engine.
// This appears to be the _first_ DLL routine called by the engine, so we
// do some setup operations here.
void WINAPI GiveFnptrsToDll( enginefuncs_t* pengfuncsFromEngine, globalvars_t *pGlobals )
{
	memcpy(&g_engfuncs, pengfuncsFromEngine, sizeof(enginefuncs_t));
	gpGlobals = pGlobals;
}

Last edited by The Storm; 20-05-2008 at 16:37..
  
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump



Powered by vBulletin® Version 3.8.2
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
vBulletin Skin developed by: vBStyles.com