Hello, I'm relatively new to C++. I've worked in C# and Java a fair amount, so I have a fairly decent understanding of programming concepts.
I've recently starting working on a mod for HL2 (not as anything commericial, just as a way for me to dive headfirst into c++ and start learning).
I've been playing for a few days, and I've run into an issue that I think (or, at least, hope) is language specific, and I don't quite grasp the symantics fully.
Anyway, I have a method of an object CBaseWeaponClip::SetMaxSize. It's code follows:
Code:
void CBaseWeaponClip::SetMaxSize( int maxSize ) {
m_iClipSize = maxSize;
// Clips hold at least a single bullet
if ( m_iClipSize < 1 ) { m_iClipSize = 1; }
if (m_iBulletsInClip > m_iClipSize) {
m_iBulletsInClip = m_iClipSize;
}
}
In another object I have a pointer
Code:
CBaseWeaponClip * c_cActiveClip
I found out that the pointer changing was causing several bugs (and it didn't need to be changing), so for safety I relabled my pointer:
Code:
CBaseWeaponClip * const c_cActiveClip
and changed other code using c_cActiveClip in that class appropriately.
However, now when I run the game it crashes and tells me "The memory at location [memory location] could not be read."
I tracked the problem to this function. Specifically changing it to:
Code:
void CBaseWeaponClip::SetMaxSize( int maxSize ) {
return;
/*m_iClipSize = maxSize;
// Clips hold at least a single bullet
if ( m_iClipSize < 1 ) { m_iClipSize = 1; }
if (m_iBulletsInClip > m_iClipSize) {
m_iBulletsInClip = m_iClipSize;
}*/
}
allows the game to load and run correctly (except weapon clips are no longer implemented properly), because SetMaxSize is a critical function. I moved my "return" statement down one line:
Code:
void CBaseWeaponClip::SetMaxSize( int maxSize ) {
m_iClipSize = maxSize;
return;
// Clips hold at least a single bullet
/*if ( m_iClipSize < 1 ) { m_iClipSize = 1; }
if (m_iBulletsInClip > m_iClipSize) {
m_iBulletsInClip = m_iClipSize;
}*/
}
and I recieved the crash again.
I got rid of the maxSize variable (well, it was still being passed), and simply assigned 5 to m_iClipSize:
Code:
void CBaseWeaponClip::SetMaxSize( int maxSize ) {
m_iClipSize = 5;
return;
// Clips hold at least a single bullet
/*if ( m_iClipSize < 1 ) { m_iClipSize = 1; }
if (m_iBulletsInClip > m_iClipSize) {
m_iBulletsInClip = m_iClipSize;
}*/
}
and I still recieved the crash.
I am assuming (quite possibly incorrectly) that relabling my pointer "const" somehow is restricting me from modifying variables like m_iClipSize. Is this the case?
If so, what is the proper fix? (It this was "mutable" was designed for?)
If not, what am I missing, or what information do I need to include?
As an afterthough it may be important: I am running Windows XP, with the Visual Studio 2003 compiler.
Thank you for your time, and I appreciate any responses.