LinuxQuestions.org
LinuxAnswers - the LQ Linux tutorial section.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
LinkBack Search this Thread
Old 02-13-2012, 09:49 PM   #1
Los Frijoles
LQ Newbie
 
Registered: Feb 2012
Posts: 2

Rep: Reputation: Disabled
gdb can't access memory of a segfault?


As the title suggests, I am having a problem with a segfault which might be because of a class being unable to access memory.

I am attempting to make a tetris clone to re-learn Ogre and so I created a TetrisApplication class that encapsulates the main application and also receives the frame synchronization events from Ogre. This class has an array of pointers to a TetrisBlockBase class which is basically a single block on the tetris board (the array is a board). Every frame, the program iterates through every pointer and if it isn't null it executes the OnRender method in the TetrisBlockBase that it points to. Here is the problem:
Code:
bool TetrisBlockBase::OnRender(float timeSinceLastFrame)
{
    bool destroyMe = false;

    if (this->moving) //segfault here
    {
...
Here is the class declaration for TetrisBlockBase:
Code:
class TetrisBlockBase
{
    public:
        //constructor: mx and my are in game grid coordates: 0,0 being the bottom left corner and 9,19 being the top right corner. mNode is an already initialized scene node
        TetrisBlockBase(Ogre::SceneNode* node, int mx, int my);
        virtual ~TetrisBlockBase();

        TetrisKnockResult Knock(TetrisKnockCondition* condition); //This is called when this block needs to be knocked

        bool DescendTo(int y); //this is called to make the block descend to a new position. Returns false if it is unable to move because the requested y is too high.
        bool AtRequestedLocation(); //returns true if the scene node's position matches the game grid coordinates requested (i.e. is the movement animation finished?)
        bool OnRender(float timeSinceLastFrame); //if this returns false, this object should be destroyed. This is called just before the frame is to be rendered
    protected:
        Ogre::SceneNode* mNode;

        int gx, gy; //the game grid coordinates of this block

        int request; //requested game grid y coordinate

        bool knocked; //whether or not this block is knocked
        bool moving; //whether or not this block is moving down
        Ogre::Vector3 acceleration; //acceleration of this node if it is knocked or moving
        Ogre::Vector3 velocity; //velocity of this node if it is knocked or moving
};
Now, when it reaches that point with the segfault in gdb I ask gdb to 'print this->moving' and it says that access is denied to '0xdeadbeef' or whatever (a non-zero value). In the constructor for the TetrisBlockBase it sets moving to false and it seems to work just fine doing that. It is just the reading of moving in the OnRender event which causes problems.

Does anyone see what my problem could be?

If I didn't explain myself well enough just say so and I will try to describe my problem in more detail. Thanks in advance!

Last edited by Los Frijoles; 02-13-2012 at 09:50 PM.
 
Old 02-14-2012, 10:16 PM   #2
KenJackson
Member
 
Registered: Jul 2006
Location: Maryland, USA
Distribution: Fedora, Arch
Posts: 488

Rep: Reputation: 58
My first guess would be the value of this.
Is it NULL?
Was the object allocated and initialized?
Are you accessing the object by a pointer that got corrupted?
 
Old 02-14-2012, 10:26 PM   #3
Los Frijoles
LQ Newbie
 
Registered: Feb 2012
Posts: 2

Original Poster
Rep: Reputation: Disabled
I also posted this on another forum and I got a suggestion there that actually resulted in me figuring out what was wrong. I wasn't initializing the whole array to NULL so there were some non-zero values floating around that weren't really pointers, but that were able to be followed a little bit just by luck (it checked for a non-zero value in the array and assumed it was a pointer and so it followed it). Only half the array was NULL'd (I substituted a 10 for a 20 in a for loop), so I guess it was one of those dumb mistakes hahaha.

Thanks.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] gdb reports "Cannot access memory at address 0x8049088". stf92 Programming 3 07-11-2011 06:11 PM
analyzing C program core dump using GDB (Cannot access memory) m4rtin Programming 3 08-31-2010 03:27 PM
GAS : Assembler Code for writing to memory :Segfault Saptarshi4031 Linux - Software 4 07-20-2010 03:33 AM
C++: use gdb to find where segfault happens Ephracis Programming 10 03-09-2009 07:42 PM
gdb : Cannot access memory at address 0x99f825d4 johnpaulodonnell Linux - Newbie 1 03-23-2007 08:14 PM


All times are GMT -5. The time now is 04:36 AM.

Main Menu
 
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: @linuxquestions
Open Source Consulting | Domain Registration