Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Dark GDK / undefined class errors

Author
Message
tomtetlaw
15
Years of Service
User Offline
Joined: 18th Jan 2009
Location:
Posted: 6th Feb 2010 00:54
when i run my code, i get lots of undefined class errors, even though i have defined and included the files properly(i think).

here are the errors i'm getting:


and this is the relevant code:
globals.h:


entitycontroller.h:


any help would be appreciated

dark coder
21
Years of Service
User Offline
Joined: 6th Oct 2002
Location: Japan
Posted: 6th Feb 2010 05:01
Quote: "class CEntityController;"


This is a declaration, not a definition.

To use a class by its object(i.e. not a ref or ptr) you must first define it, this requires you include 'entitycontroller.h', but this includes 'globals.h' for no reason so it may not work.

As a general rule of thumb, you only really need to include a file from a header if you're going to use an object directly, such as a data member, like so: 'CEntityController controller;', or as a method argument, or if you're inheriting. In all other cases you can just add a forward reference, like so: 'class CEntityController;' Thus in a lot of cases you don't have to include much from the headers.

tomtetlaw
15
Years of Service
User Offline
Joined: 18th Jan 2009
Location:
Posted: 6th Feb 2010 09:08
That fixed it, but now I am getting a runtime error.

Unhandled exception at 0x004ccf99 in engine.exe: 0xC0000005: Access violation reading location 0x0000001c.
That is the error.

It points to this code from <vector>:



this is the code dealing with vectors:


dark coder
21
Years of Service
User Offline
Joined: 6th Oct 2002
Location: Japan
Posted: 6th Feb 2010 09:27
You can debug this yourself, the stuff from your first snippet box was found from the stack trace I assume, you can double click on entries lower down the stack until you come across your code and you can see where the problem is. I would assume the problem is you trying to deference a member of a class that hasn't been instanced.

tomtetlaw
15
Years of Service
User Offline
Joined: 18th Jan 2009
Location:
Posted: 6th Feb 2010 10:27
I don't know if it was from the stack trace, VC++ just opened that file and put an arrow next to that function. How do I look at the stack?

dark coder
21
Years of Service
User Offline
Joined: 6th Oct 2002
Location: Japan
Posted: 6th Feb 2010 10:52
When you hit the error and press 'Break' you should see THIS.

tomtetlaw
15
Years of Service
User Offline
Joined: 18th Jan 2009
Location:
Posted: 6th Feb 2010 11:27 Edited at: 6th Feb 2010 11:28
It's telling me that the code that is causing the problem with the vector is this:


The code that calls that code is this:



And the constructor code is here:


I still don't understand why this error is happening, so I hope I have given you enough information

dark coder
21
Years of Service
User Offline
Joined: 6th Oct 2002
Location: Japan
Posted: 6th Feb 2010 13:51
If the error is when 'AddEntity' is called and you call that from 'gpGlobals->controller.AddEntity( this );' then it may help if you show me what these things are. In addition to viewing the stack trace, when in that debugging mode you can also hover over all variables visible from that stack level and see their values! I suggest you do this for everything inside of 'gpGlobals->controller.AddEntity( this );' starting with gpGlobals.

tomtetlaw
15
Years of Service
User Offline
Joined: 18th Jan 2009
Location:
Posted: 6th Feb 2010 22:28
AddEntity is a member of CEntityController(controller)

entitycontroller.h:


entitycontroller.cpp


gpGlobals is of the type CGlobals:

globals.h:


globals.cpp:


And apparently gpGlobals = 0x00000000, I think this means that it's NULL.
Should I just go for not making it a pointer or is there another way?

tomtetlaw
15
Years of Service
User Offline
Joined: 18th Jan 2009
Location:
Posted: 6th Feb 2010 22:36 Edited at: 7th Feb 2010 00:11
Yep, I changed gpGlobals to NOT be a pointer, and I no longer get a runtime error. But I found out that my timer system doesn't work, what it's supposed to do is:
- Every class based from CBase(entities) has a member called m_fNextThinkTime, and whenever gpGlobals.curtime >= m_fThinkTime of that class, that class's Think( ) function is called. But I have a bug in the code and that function doesn't ever get called, I tested it using this code:



gpGlobals.curtime is measured in milliseconds, which I think is 0.001f in code, is this right?

gpGlobals.curtime is updated by gpGlobals.timer, here is the code for it:

timer.h:


And here is where it's updated:


Loop get's called every frame.

I set up a breakpoint and it seems that at 7 seconds(approx.), gpGlobals.curtime == 0.49999711, this is wierd because it should be 7.00, or atleast, that's what I want it to do.

I don't really know how to find the cause of this bug so any help would(and has been!) really appreciated.

tomtetlaw
15
Years of Service
User Offline
Joined: 18th Jan 2009
Location:
Posted: 7th Feb 2010 00:44
It's okay, I fixed it, I just had to add a different amount to gpGlobals.curtime, because there wasn't one frame going a second.

Login to post a reply

Server time is: 2024-10-01 23:30:44
Your offset time is: 2024-10-01 23:30:44