Jump to content
  • Advertisement
Sign in to follow this  
  • entries
  • comments
  • views

Uninitilized pointer worked for weeks!

Sign in to follow this  



Today has started out as a typical day of programming. After making some modifications to the code to fix some warnings and split the code into smaller routines, I rebuild and test.

invalid instruction!

Okay I thought. Ill just undo the changes and try it again:

general protection fault!

Eek! At this point I was having no idea what was going on. The code worked fine for weeks without any problems; what can cause this to happen now? I decided to go back even further to see if it was any of the newer code:

invalid instruction!

*ugh*. After going through my code, I found out I was working with a pointer that was never initialized. The system uses a single singleton class called core that provides a basic set of routines that need to be used across all other classes. Thus everything uses it. All of them obtain the pointer from this routine:
core* core::get () {

return m_core;

Keep in mind that this is self hosted running in ring 0. And all classes are using m_core to print strings, call bios interrupts, and more...and it worked fine for weeks until now.

The fix for it was simple--just have m_core point to a known valid address. Not having a memory manager nor wanting to point to specific locations in memory, I decided to have the compilier do it:
core* core::get () {

if (!m_core) {
static core pkCore;
m_core = &pkCore;

return m_core;

After this change everything seems to be working fine now.

I have no clue of how this managed to work before just fine (even on raw hardware) without any problems :/ I am glad the problem turned up now though before it became a bigger issue!

If anyone knows how it managed to work for weeks ill give you a free cookie [wink]
Sign in to follow this  


Recommended Comments

There are no comments to display.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • 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!