Jump to content
  • Advertisement
Sign in to follow this  
SilverLogic

Engine Trouble...

This topic is 5408 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hey guys, im trying to program a game engine, the exe compiles just fine, 0 errors 0 warnings, ive looked over my code, i dont see anything wrong, but im getting very strange errors. for instance, 1) int mp_iColorDepth, i assign this variable a 32, then, somehow it gets turned into a 776 2) when i run the exe, i get a code block reference and a memory address saying the memory cannot be written. Maybe you know whats wrong?? You can look at my code here (its small, only 16 kb) Clicky It uses SDL and OpenGL, so youll need those libraries to compile, otherwise the code is pretty straight-forward maybe you could just glance and tell me i just made a stupid mistake :(

Share this post


Link to post
Share on other sites
Advertisement
Just because you don't have any syntax errors, doesn't mean you don't have logic errors. That's why you're supposed to put assert() statements at the beginning and end of all your functions, to validate your assumptions.

Anyway, to debug a variable that gets clobbered, the easiest way is to do this:

1) Set a breakpoint where the variable initially gets assigned.
2) Run to that breakpoint.
3) Step over the assignment, so the variable has the right value.
4) Evaluate "&m_myVariable" in the Watch window to get the address of the variable. (no quotes) This will be an address, something like 0x214056c.
5) Add a new breakpoint, as a "Data" breakpoint, saying "Break when the value ... changes". For the data value, say "*(long*)0x214056c" (where you actually enter the address you got out of step 4).
6) Continue the program.

When the variable gets changed, the debugger will break -- it's magic! Typically, you'll find that you're breaking somewhere inside memcpy() or a similar function, and if you walk up the stack at that point (you may have to shift-F11 out of memcpy() one or a few times to get your stack back) you will see that you're passing the wrong address of some sort, or too long a count, or something similar that will cause an overrun/overwrite.

Share this post


Link to post
Share on other sites
The first line in main():
Engine->Window->InitWindow(800, 600, false);


The engine needs to have a constructor that creates a window. Set a breakpoint on that line and you'll find that Engine->Window is an invalid pointer.

You will also need to make the logicWindow constructor and destructor public. If they're protected then only member functions and functions in derived classes will be allowed to create logicWindow objects, which is probably not what you want.

Share this post


Link to post
Share on other sites
The first thing I notice with your code is you are using the variable pointer "Window" without creating it; I'll assume this is why you are getting memory write access errors.

Also you seem to be creating a global variable pointer "Engine" on the top of main.cpp, and not cleaning it up (memory leak..) - I'd suggest a singleton be used in a case like this.

Fix those two problems and see what happens. My best bet is that class variables are getting over-ridden by something else because "Window" isn't a valid pointer.


-Nate S.

Share this post


Link to post
Share on other sites
But you are using it before it is valid. Also you are only creating one pointer in your entire engine - which is the pointer "Engine" on the top of main.cpp


-Nate S

Share this post


Link to post
Share on other sites
Window in Engine is not initialized.

EDIT: Damn. Waaaayyyyy too slow :P It took me ages to get rid of the damn SDL linker errors...

Share this post


Link to post
Share on other sites
Could you explain? I thought by putting the pointer to window in the engine, and then creating a global pointer to engine, that i could access it from the main engine pointer?

Share this post


Link to post
Share on other sites
You've created the pointer, but you haven't given it a value. It has nothing to point to.

int *pointer;
*pointer = 5; // Crash!

int i;
int *pointer = &i;
*pointer = 5; // OK

int *pointer = new int;
*pointer = 5; // OK
delete pointer; // always clean up when you're done with it!

Share this post


Link to post
Share on other sites
How about this, send me a message on either AIM/MSN and I'll walk you through fixing your code. Posting messages back and forth on the forum is rather time consuming =P

MSN: nstrg@hotmail.com
AIM: freesetup


-Nate S.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!