Simple C++ Fog Problem

I am new to using Panda and have been just messing around with simple things so far using the simple environment shown in the manual. My problem is that I am trying to simply add fog to the manual hello world project. I feel like I’m just missing something very simple. Everything compiles fine… but when I run i get a Runtime error.

#include "stdafx.h"
#include "pandaFramework.h"
#include "pandaSystem.h"
#include "fog.h"

PandaFramework framework;

int _tmain(int argc, char *argv[])
	framework.open_framework(argc, argv);
	framework.set_window_title("My Panda3D Window");

	WindowFramework *window = framework.open_window();

	NodePath cam = window->get_camera_group();

	//load the environment model
	NodePath environ = window->load_model(framework.get_models(),"models/environment");

	PT(Fog) myFog;
	myFog = new Fog("Scene Fog");

	//do the main loop:
	ClockObject* clock;
	clock = ClockObject::get_global_clock();
	Thread *current_thread = Thread::get_current_thread();
		double time = clock->get_real_time(); 
		double angledegrees = time * 6.0;
		double angleradians = angledegrees * (3.14 / 180.0); 
		cam.set_hpr(angledegrees, 0, 0); //set the hpr
	//close the window framework
	return (0);

Any help would be greatly appreciated. I have found it to be semi-difficult to find any resources/samples for Panda3d in c++ :frowning: .

Thanks in advance.

I’ve tried your code, and it works perfectly fine for me. I can see the Hello World sample with a fog.

What is the exact error you’re getting?

I am not completely sure to be honest with you. I get a popup window saying TestPanda.exe has encountered a problem and needs to close. We are sorry for the inconvenience. Then you have the buttons for Debug, Send Error Report, and Don’t Send.

If I press debug… I get the following…

Is there a chance that my configuration properties of my project in visual studio are messed up and could be causing this problem? I have included the following include files:

As well as the following library directories:

And included the following dependencies:

The libraries look correct to me.
Can you get MSVC to show you the line of code in which the problem occurs?

The problem occurs once this line is put into the code:

myFog = new Fog("Scene Fog");

Without that in there… it works just fine… without the fog obviously.

No, I mean the line of code at which it crashes - in the Panda3D source.

Maybe you are missing a library file or something. like in Additional dependencies. I dont know, just a thought

How exactly can i figure out which line in the Panda3D source is causing the crash?

And as far as the libraries added… they are listed above… so if you notice anything I am missing… let me know and I’ll give it a try.

I also get the same problem when I attempt to use lights…

PT(AmbientLight) myLight;
myLight = new AmbientLight("Ambient Light");
myLight->set_color(LVecBase4f(.5, 0, 0, 1));
NodePath pAmbient = window->get_render().attach_new_node(myLight);

Hmm, does the problem also occur if you use ordinary pointers?

   Fog* myFog;
   myFog = new Fog("Scene Fog");

Yep the same exact problem still occurs even with ordinary pointers.

Well I tried your code, it works fine for me too.

The only problem I seem to be having is that when i close my window it stops working.
and when i take the FOG code out is closes normally.

I do have a question. What is the difference between main() and _tmain()
I tried using it and I had errors. I have never seen that before.

Huh, this is all very strange. I certainly don’t see any problem with the above code.


I don’t see any problem with the code either. Yet it crashes every time. It will load the model and render it. I can see the fog… then a second after it starts running… crash. There has to be something little I am doing wrong. I can easily duplicate the code in python and I have no problems. However, when I create it in c++ I have this crashing problem. I am fairly certain I have everything setup correctly… is there a certain type of project I should create to begin with? I have just been using a Win32 Console Application. Do I need to use something other than that?

Under C/C++>>Processor>>Processors Definitions Do you have anything there??

I used to have this :

and it stopped working. now i took it out and it doesnt do that anymore.

Dunno if it will help.

but just a thought.

Also check that the Code Generation>>Runtime Library: is Multi-Threaded DLL(/MD)

but you may already have this setup.


I already had that in my preprocessor definitions and I already have the multithreading setup… so still not working. I did find something interesting though. It seems that if I use the setup_trackball mouse settings and just run the main_loop instead of the setup I posted above with the rotating camera… I don’t seem to have any problems.

Note: The rotating camera setup works fine with out the fog added in there.

Any ideas?

It really seems like something is corrupt in your build somehow; the sorts of errors you’re describing seem random and unrelated to the particular changes you’re making.

Do you know how to use the Microsoft debugger to view the stack trace at the time of the crash? It might be informative to know what line is actually crashing.

Did you build this Panda yourself, or are you using the supplied build?


I am using the supplied build. And the same crash is happening on both of my computers.

And when looking at the call stack…