krid
March 12, 2010, 4:59am
1
hi, i try to port the python motion trail code into c++. my application crash without a regular error.
what im doing wrong?
//make a texture
PT(GraphicsOutput) buffer;
PT(Texture) bufferTEX;
PT(Camera) backcam;
buffer->add_render_texture(bufferTEX,GraphicsOutput::RTM_triggered_copy_texture);
//create a new camera
backcam = new Camera("backcam");
NodePath background= window->get_camera_group().attach_new_node(backcam);
background.set_depth_test(0);
background.set_depth_write(0);
NodePath bcard = window->get_graphics_output()->get_texture_card();
bcard.reparent_to(background);
NodePath fcard = window->get_graphics_output()->get_texture_card();
fcard.reparent_to(window->get_render_2d());
drwr
March 12, 2010, 6:21am
2
PT(GraphicsOutput) buffer;
buffer->add_render_texture(bufferTEX,GraphicsOutput::RTM_triggered_copy_texture);
When you code in C++, you have to be more careful than when you use Python. In particular, you have to be careful about NULL and uninitialized pointers, things which generally aren’t possible in Python.
Here, you have declared the pointer “buffer”, but you haven’t initialized it to anything; then you try to call buffer->add_render_texture(), which is going to crash hard because buffer doesn’t point to a valid object.
David
krid
March 12, 2010, 8:19am
3
cool, thank you!
yes i need to learn alot, i thought, i initialized it with PT(GraphicsOutput) buffer; at the same time.
krid
March 12, 2010, 8:44am
4
cool now its working.
//make a texture
PT(GraphicsOutput) buffer;
PT(Texture) bufferTEX;
PT(Camera) backcam;
buffer = window->get_graphics_output()->make_texture_buffer("Buffer", 128, 128);
buffer->add_render_texture(bufferTEX,GraphicsOutput::RTM_triggered_copy_texture);
//create a new camera
backcam = new Camera("backcam");
NodePath background= window->get_camera_group().attach_new_node(backcam);
background.set_depth_test(0);
background.set_depth_write(0);
NodePath bcard = window->get_graphics_output()->get_texture_card();
bcard.reparent_to(background);
NodePath fcard = window->get_graphics_output()->get_texture_card();
fcard.reparent_to(window->get_render_2d());