Project forums > Q-Gears

That #@&!! linux segfault is still there ;_;

<< < (2/4) > >>

dziugo:

--- Code: ---    int i;
    for(i = 0; i < 10; i++){
        cout << i << endl;
    }
    cout << endl;
    for(i = 0; i < 10; ++i){
        cout << i << endl;
    }
--- End code ---
Run it...

halkun:
Here's something I got in my email today....


--- Quote ---First off, just wanted to say that I really hope this project gets off the ground. I'm a big fan of tearing into things to check out the inner workings and I can tell you are as well.

On the forum, you posted:

    void ScreenManager::Draw()
    {
        DISPLAY->BeginFrame();
    /*
        for (int i = 0; i < mScreens.size(); ++i)
        {
            mScreens->Draw();
        }
    */
        for (std::vector<Screen*>::iterator i = mScreens.begin(); i != mScreens.end(); ++i)
        {
            (*i)->Draw();    //Segfaults here!
        }

        DISPLAY->EndFrame();
    }


There are a couple things that could cause that line to crash. I don't have the full code in front of me so I'll just list them and leave it to you to ignore anything that isn't applicable.

- if "ScreenManager::Draw()" is a non-virtual function, and "DISPLAY" is not a member variable, the "this" pointer for the function call could be null or otherwise invalid. I'd consider this unlikely because then I would expect it to crash initializing "i" during the "mScreens.begin()" call.

- *i evaluates to null or an otherwise invalid pointer. The iterator itself can be entirely valid but iterating over contents that are invalid for your purposes. How are you adding and removing Screen* objects from the vector? Is it possible that you're deleting or corrupting a Screen object somewhere but never removing it from the vector? Something like the following should definitely crash:

{
  // Allocate a new object.
  Screen *screenObject = new Screen(...);

  // Insert the new object into the list of screens.
  mScreens.push_back( screenObject );

  // Delete the memory that we just allocated. Note that after we do this
  // there is still one element in mScreens, pointing to where there *used*
  // to be a Screen.
  delete screenObject;

  // This will then crash as we call a function on a dead pointer.
  for (std::vector<Screen*>::iterator i = mScreens.begin(); i != mScreens.end(); ++i)
    (*i)->Draw();
}

- Draw() is a virtual function on the Screen class and the virtual table on the object in question is hosed somehow. I'd consider this unlikely unless you're doing strange pointer arithmetic or using C-style memset() in funny ways, but it's possible.

I'd consider the above the most likely possibilities. Any help?

    Also, could you put the increment operater after the variable if it's not critical to have? That just looks wierd.


Yeah. The only difference is that the code internally has to store off a temporary value if you do a post-increment (i++). The difference boils down to something like this, in made-up pseudocode:

function ++i ( int i )
{
  return i + 1;
}

function i++ ( int i )
{
  int old_i = i;
  i = i + 1;
  return old_i;
}

Neither you nor the expressions you're using it in care about the return value and so the compiler is almost definitely smart enough to optimize them out to be equivalent.


--- End quote ---

I still think the display code is overly complex for what we need it to do. Can someone tell me why a simple opengl double-buffer isn't good enough?

Akari:
Halkun, try this.
http://server.titansoft.ru/akari/screenmanager.cpp
and check log file after executing.


--- Quote ---Can someone tell me why a simple opengl double-buffer isn't good enough?
--- End quote ---

We use simple opengl double-buffer. We just incapsulate it into Display class. If you check functions content - there are usual glDrawArrays in there =)

halkun:
from game.log


--- Quote ---[03:36:37] GLU Version: 1.3
[03:36:37] Set SDL input handler.
[03:36:38] Size of mScreens 0

--- End quote ---

Then a segfault

Does that help?

##############
EDIT
##############

I made a teeny change to the code...
Here's what I added.


--- Quote ---ScreenManager::Draw()
{
    DISPLAY->BeginFrame();
                                                                               
    for (int i = 0; i < mScreens.size(); ++i)
    {
         LOGGER->Log("ERROR: Loop in"); //added this to see if simply refrencing the pointer causes it to nuke
        if (mScreens != NULL)
        {
            LOGGER->Log("ERROR: ready to draw");  //Added this too to, just to see if I enter the loop.
                                                                               
            mScreens->Draw();
        }
        else
        {
            LOGGER->Log("ERROR: Here it is... - NULL pointer.");
        }
    }
                                                                               
    DISPLAY->EndFrame();
}

--- End quote ---




--- Quote ---[03:40:35] ERROR: ready to draw
[03:40:35] ERROR: Loop in
[03:40:35] ERROR: ready to draw
[03:40:35] ERROR: Loop in
[03:40:35] ERROR: ready to draw
[03:40:35] Size of mScreens 0
[03:40:35] ERROR: Loop in
[03:40:35] ERROR: ready to draw

--- End quote ---
*SEGFAULT*

Akari:
Then we just have easy error in

void
ScreenDisplayTest::Draw()
{
    DISPLAY->SetPointSize(3);
    DISPLAY->DrawPoints(mPoints);
    DISPLAY->SetLineWidth(1);
    DISPLAY->DrawLines(mPoints);

    DISPLAY->PushMatrix();
    DISPLAY->RotateX(mRotation);
    DISPLAY->DrawTotalGeometry(mPyramid);
    DISPLAY->PopMatrix();
    ++mRotation;

    DISPLAY->TextureTranslate(0.01f, 0.0f);
    DISPLAY->SetTexture(mTexId);
    DISPLAY->DrawQuads(mQuadsTex);
    DISPLAY->UnsetTexture();
}

I has the same error but I fix it for me, as I see not compleatly. Try to comment some of rows in this method in DisplayTest.cpp

I has error here, check this first.
    DISPLAY->PushMatrix();
    DISPLAY->RotateX(mRotation);
    DISPLAY->DrawTotalGeometry(mPyramid);
    DISPLAY->PopMatrix();
    ++mRotation;

Just as I thought its not a matter of ScreenManager after all.

Navigation

[0] Message Index

[#] Next page

[*] Previous page

Go to full version