Resources > Coding

Game engine resources?

<< < (3/4) > >>

MG-Zero:

--- Quote ---when I used C++, a variable in my class was apparently being overwritten or something, somehow, causing very undesirable results.
--- End quote ---

Yes, C# allows you to do that too.  You probably had 2 pointers to the same variable and modified one of them, therefore modifying the original variable.  C# allows this same thing through reference types.  Or you did a buffer overflow (less likely).  Which is undefined behavior and can cause all kinds of mayhem.

LorentzChronon:

--- Quote from: HylianGoombario on March 04, 2015, 06:54:12 am ---I'm just saying that, when I used C++, a variable in my class was apparently being overwritten or something, somehow, causing very undesirable results.

--- End quote ---

To be honest, you can do the same exact thing in C# if you are not careful. Like MG-Zero said, you probably had two references pointing to the same address -- which can happen in C# too. This can be avoided by staying organized and being aware of what you're doing -- which is a concept global to computer science in general.

HylianGoombario:
I'm totally aware that it's possible, if you're using a pointer. It's been so long, and I probably don't even have the source anymore, but the variable in question was the one that told the Draw function which sprite in the sheet to draw. It was malfunctioning after I set another variable. It was as if I had "made too many variables" or something. It was literally the declaration of a variable tht broke my engine.

I was new so I consulted someone else, who told me it was probably a memory management error, and that memory management was less manual in C#. I listened.

LorentzChronon:

--- Quote from: HylianGoombario on March 04, 2015, 05:28:55 pm ---I'm totally aware that it's possible, if you're using a pointer.

--- End quote ---

All variables that point to an object in C# are technically pointers to that object (aka reference types). Are you saying you were using a value type (int, double, etc...) and it was still overriding the reference?


--- Quote from: HylianGoombario on March 04, 2015, 05:28:55 pm ---It's been so long, and I probably don't even have the source anymore, but the variable in question was the one that told the Draw function which sprite in the sheet to draw. It was malfunctioning after I set another variable. It was as if I had "made too many variables" or something. It was literally the declaration of a variable tht broke my engine.

I was new so I consulted someone else, who told me it was probably a memory management error, and that memory management was less manual in C#. I listened.

--- End quote ---
This doesn't really make any sense, unless you got the too many variables error from adding excessive parameters to a function. Otherwise, it sounds like a mistake was made in the code that probably threw you and your friend off the trail.

If you have any specific questions that you need help on with C# (or other languages even), feel free to post snippets of code here.

MG-Zero:
The thing with C/C++ is that it lets you do whatever the hell you want, regardless of whether or not the specification regards it as undefined behavior.  When you DO do something undefined however, things get wacky.  Writing too much data to a buffer, returning the address of local memory etc.  When you do these types of things, the behavior of the program is no longer predictable and strange things such as overwriting of variables can occur.

Navigation

[0] Message Index

[#] Next page

[*] Previous page


Contact Us | Legal | Advertise Here
2013 © ZFGC, All Rights Reserved



Go to full version