Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GetHullBounds handles vector copying incorrectly #1703

Open
SamVanheer opened this issue Jun 12, 2016 · 6 comments
Open

GetHullBounds handles vector copying incorrectly #1703

SamVanheer opened this issue Jun 12, 2016 · 6 comments

Comments

@SamVanheer
Copy link

The GetHullBounds function in client.cpp handles vector copying incorrectly.
Link to code:

int GetHullBounds( int hullnumber, float *mins, float *maxs )

It assigns the bounds vectors to a float*. All this does is set the function argument to point to that vector (which is a local variable). It doesn't modify the actual vector stored in the engine.

The same thing happens on the client side:

int CL_DLLEXPORT HUD_GetHullBounds( int hullnumber, float *mins, float *maxs )

Both functions do the same thing, and neither actually set the bounds in the engine.

You can verify this by printing out the contents of the array that the arguments point to upon entry of the function. They are unmodified.

The engine uses the same values as those set in the SDK, so you won't notice any problems if you leave them unchanged.

Note that if you fix this, you must fix it for both functions. The same memory is used by the client and server, so if only one of them is fixed, you will end up with code going out of sync if the bounds are changed.

@JoelTroch
Copy link
Contributor

So changing the function prototype to this :

int GetHullBounds( int hullnumber, float &mins, float &maxs )

On both sides should fix the issue or am I wrong ?

@SamVanheer
Copy link
Author

No, if you want it to work properly and be simple, you should use Vector&:
int GetHullBounds( int hullnumber, Vector& mins, Vector& maxs )

You'll have to change the function prototypes, but it won't break anything.

Alternatively, if you don't want to change it, memcpy the vectors:
memcpy( mins, &VEC_HULL_MIN, sizeof( float ) * 3 );

I'm assuming it will allow you to take the address of VEC_HULL_MIN (it probably won't). I used the Vector& solution since it's the simplest, and since it makes the code easier to work with.

@JoelTroch
Copy link
Contributor

Alright, thanks for sharing

@tschumann
Copy link

Nice - you should add a pull request to fix this.

@SamVanheer
Copy link
Author

I'll see if i can put together a pull request for this then.

@SamVanheer
Copy link
Author

SamVanheer commented Jun 30, 2016

Ignore the first commit, it was made in the wrong branch.

EDIT: removed the wrong commits.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants