Forward Declaration of Class breaks the game

Started by
20 comments, last by NightCreature83 10 years, 10 months ago

How do you create your CMainGame object? Put a breakpoint in your CMainGame constructor and your CMainGame::OnUpdate funtion and make sure the constructor is called before CMainGame::OnUpdate is called.

Looks like you aren't creating the CMainGame object before calling methods on it.

"Most people think, great God will come from the sky, take away everything, and make everybody feel high" - Bob Marley
Advertisement

<twilight zone music playing in the background>

0x00000026? that's weird... blink.png

// This is literally how its created
#include "stdafx.h"
#include <engine.h>
#include "MainGame.h"
int main(int argc, char* argsv[])
{
CMainGame* theGame = new CMainGame();
theGame->Run();
return 0;
}
when I put breakpoints in the constructor and on update, first it breaks at constructor. And everything exists then, it is not null. When I press F5 it goes to the Update and then its 0x0000026 again. Could it be because of this in MainCharacter.h ?
class CMainGame;
class CMainCharacter
{
public:
But when I remove that line I get that:
error C2061: syntax error : identifier 'CMainGame'

At this point i think you should post the whole thing

Just as a curiosity but you do include CMainGame in the cpp file of CMainCharacter right? Because as soon as you want to use any of the function of CMainGame in CMainCharacter it needs to know the type properly so you can't call any function on it in the header.

Also are you compiling debug or release, because if you are in release the Camera function and AI update function calls before hand can invalidate the debuggers view of the this pointer, and you will have to inspect the disassembly to see which register is holding the this pointer to obtain valid values for it.

Worked on titles: CMR:DiRT2, DiRT 3, DiRT: Showdown, GRID 2, theHunter, theHunter: Primal, Mad Max, Watch Dogs: Legion

Just as a curiosity but you do include CMainGame in the cpp file of CMainCharacter right? Because as soon as you want to use any of the function of CMainGame in CMainCharacter it needs to know the type properly so you can't call any function on it in the header.

No CMainGame is included in .h file, and CMainCharacter .cpp only includes CMainCharacter.h. Ive just added it to cpp and still does the same thing
Also I was compiling in Release mode, my bad :(. In debug mode still crashing. The pointers in Update are working correctly in Debug mode... So it is not null or 0x000026... The constructor, update in main game and update in main character, the pointer values are all the same.
I'm not giving up until this is going to work... <twilight zone music playing in the background>
that music doesn't help either hehe

basically all I am trying to do is add controls functions to the MainCharacter class. I might be doing it wrong but in my engine I just inherit controls class into the main engine class. Ill just stop inheriting it and create it manually in my game, and pass that into the MainCharacter class.

I have just managed to fix it :) Thank you all for help. Problem wasn't with controls but with something else in my class :x Something very silly

Could you explain what the problem was so that people looking at the same problem in the future can find the solution?

void hurrrrrrrr() {__asm sub [ebp+4],5;}

There are ten kinds of people in this world: those who understand binary and those who don't.

Could you explain what the problem was so that people looking at the same problem in the future can find the solution?

I've rewritten controls a little bit but this was the problem:

CMainCharacter::CMainCharacter(CPhysics* Physics, collisionListener* theCollisionListener, controls* passedControls)
{
theControls = passedControls;

theCollisionListener = theCollisionListener;

....

theCollisionListener was set to itself instead of

this->theCollisionListener = theCollisionListener;

Then it was breaking on

if (theControls->isKeyHold(SDLK_a)) ///this line!

{
if (!theCollisionListener->GetAllowJump()) //but actual problem was on this line since this was null....
{
so it completely threw me off, and I was looking for the problem with controls...
Over 7 hours wasted trying to solve this stupid silly mistake!

This topic is closed to new replies.

Advertisement