Jump to content
  • Advertisement
Sign in to follow this  
S0n0

pointers

This topic is 4648 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi there, i've got a little problem using pointers and i don't know how to handle that.
// - Update client subsystem for rendering, audio and input
void Client::Tick( void )
{
  // - Viewport rendering goes here
  // - Update each viewport opened
  for( int i = 0; i < nViewports; i++ )
  {
    assert( viewport ); // - Won't crash
    // - Clear viewport and set view
    render->preCompute( viewport );
    assert( viewport ); // - Will crash
    viewport->tick( ); // - Crashes also
    // - Do something like a screen flash
    render->postCompute( viewport );
  }

}
* i'll get a segmentation violation here and don't know why. The render::preCompute will do nothing else than using some values of viewport to set the view. but afterwards the pointer will point to nirvana. Even an assert-statement will cause a crash here. Any suggestions? [Edited by - S0n0 on October 21, 2005 6:25:14 AM]

Share this post


Link to post
Share on other sites
Advertisement
There's only one thing happening between the valid assert and the invalid assert so please post the code of preCompute as well. Perhaps it does not do what you think it does.

Illco

Share this post


Link to post
Share on other sites

// - RenderDevice OpenGL implementation
void RenderDevice::preCompute( Viewport *viewport )
{
// - This is for function-call-backtrace
guard( RenderDevice::preCompute );
assert( viewport );

glViewport( viewport->x, viewport->y, viewport->w, viewport->h );
glClear( ClearFlags );

glMatrixMode( GL_PROJECTION )
glLoadIdentity( );

// - This could be wrong
glFrustum( -1.f, 1.f, -1.f, 1.f, viewport->nearZ, viewport->farZ );

glMatrixMode( GL_MODELVIEW );
glLoadIdentity( );
glRotatef( viewport->yaw, 1.f, 0.f, 0.f );
glRotatef( viewport->roll, 0.f, 1.f, 0.f );
glRotatef( viewport->pitch, 0.f, 0.f, 1.f );
// - Viewport object will exist until here
return;
unguard( );
}


[Edited by - S0n0 on October 21, 2005 6:10:03 AM]

Share this post


Link to post
Share on other sites
Well, your
assert( viewport ); // - Won't crash
doesn't check that viewpoint is a valid pointer, it only checks if it isn't NULL.

Share this post


Link to post
Share on other sites
Does the assert() fail or does it actually crash? If it fails, the viewport pointer is NULL so you can make your debugger watch that memory address for changes. If it crashes, then I guess the viewport pointer is invalid and you should watch that instead.

Share this post


Link to post
Share on other sites
I am not familiar with the guard() and unguard() functions, but one thing I noticed is that the call to unguard() is after the return; line, so it never gets executed. Could that be the problem?

Share this post


Link to post
Share on other sites
the assert is valid, means viewport is non-null. everything i know is that i never modified the data where viewport points to.

the guard- and unguard-statements are macros implementing try and catch.
an assert will throw an exception catched by the catch-directive after return.
the guard function will push the current function's name onto the stack. Is the function's name out of scope (means function has been left) the name will be popped. If an assertion fails it will throw an exception right to the unguard-statement which rewinds the stack and shows me a backtrace (which functions have been called and what happend in which file and line)

Share this post


Link to post
Share on other sites
Well, are you sure your function/class declarations are consistent? Do you have compiler warnings turned on?

Also, have you tried a "clean" or "make clean" or whatever based on your build environment? Sometimes cleaning up can help weird bugs like this sometimes :)

Share this post


Link to post
Share on other sites
thanks for the 'clean' advice, i will try, but do you mean with consistency of function/class?

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!