Sign in to follow this  
Tradone

Segmentation fault Error. What is it?

Recommended Posts

So here's the summary in simpler terms. Error Type: Segmentation fault (core dumped) error. No runtime error: Total Cycles:10
			for(int i=0; i<=10; i++){
				skin.Read( "Body" );
			}		


Runtime error: Total Cycles:4
			std::map< std::string, std::map< std::string, std::string > >::iterator loop;
			for ( loop=mainData.GetData().begin(); loop != mainData.GetData().end(); loop++ ){

skin.Read( "Body" );
 
			}


No Runtime error: Total Cycles:1
			std::map< std::string, std::map< std::string, std::string > >::iterator loop;
			for ( loop=mainData.GetData().begin(); loop != mainData.GetData().end(); loop++ ){

skin.Read( "Body" );
 break;
			}


//inside method skin.Read( const std::string );
std::cout << para_skinTypeValue.substr(0, para_skinTypeValue.find("($") );
para_skinTypeValue=para_skinTypeValue.substr(para_skinTypeValue.find("($")+2, para_skinTypeValue.length()-para_skinTypeValue.find("($")-2 );
EvaluateFunction( para_skinTypeValue.substr(0, para_skinTypeValue.find(")") ) );
para_skinTypeValue=para_skinTypeValue.substr(para_skinTypeValue.find(")")+1, para_skinTypeValue.length()-para_skinTypeValue.find(")")-1 );



and it seems like the std::cout << para_skinTypeValue.substr(0, para_skinTypeValue.find("($") ); code is fine. But the second line para_skinTypeValue=para_skinTypeValue.substr(para_skinTypeValue.find("($")+2, para_skinTypeValue.length()-para_skinTypeValue.find("($")-2 ); causes the segmentation fault error when run twice inside the iterator. but doesn't create an error when run on a regular for loop. [Edited by - Tradone on April 3, 2006 10:19:30 PM]

Share this post


Link to post
Share on other sites
I note that you're not doing anything with the iterator beside incrementing it, so what's the point?

Share this post


Link to post
Share on other sites
The reason the last is "fine" is beause of that 'break;' statement - you're never excuting the body of that loop more than once.

Share this post


Link to post
Share on other sites
They're runtime errors.
I get no errors.
none.
nada.
no seriously, this is driving me insane.

Internal Server Error

The server encountered an internal error or misconfiguration and was unable to complete your request.

Please contact the server administrator, webmaster@dummy-host.example.com and inform them of the time the error occurred, and anything you might have done that may have caused the error.

More information about this error may be available in the server error log.

this is all I get,
nothing recorded on the apache log.
no *.core file.
because it's run on the web.

the only one thing that I can do to view error messages are to execute the file directly from the console. but when I do that I get an error message as the following:

151# ./webtest.cgi
Content-type: text/html

<html>
<head>
<title>success</title>
</head>
terminate called after throwing an instance of 'std::logic_error'
what(): basic_string::_S_construct NULL not valid
Abort (core dumped)

So, all in all I can't even run the thing on the console.
but there is no error when run on the web though.

Share this post


Link to post
Share on other sites
Quote:
Original post by RDragon1
The reason the last is "fine" is beause of that 'break;' statement - you're never excuting the body of that loop more than once.


I put a break; there to test if the errors will persist even when the Read is performed only once.

well, the first thing I should do is make the program run on the console b/c I don't know what's causing the problem. It took me about an hour to trace it back to my first post.

and while I'm doing that I'll double check if skin.Read() makes changes to mainData along the way.


Share this post


Link to post
Share on other sites
okay, I got it to run on the console.
that wasn't so hard, :D
Got rid of the

terminate called after throwing an instance of 'std::logic_error'
what(): basic_string::_S_construct NULL not valid
Abort (core dumped)


Errors.
If you're interested check out this link.
http://www.gamedev.net/community/forums/topic.asp?topic_id=385125

and since my program runs on the web, parameters must be fed, so in order to run it on the console I had to use command link arguements
http://www.site.uottawa.ca/~lucia/courses/2131-05/labs/Lab3/CommandLineArguments.html

and so I finally got it to work, and the error messages are

Segmentation fault (core dumped)



and if any of you developers know any debugging methods, or have any debugging tools. Thanks. ( I wonder if the VS Express debugging tools actually work )

Share this post


Link to post
Share on other sites
How many elements are in the map when you run the second example?
Plus, try experimenting with a std::map without another map inside of it, just for testing purposes (in another project, of course). See if you get the same kind of error when running it in a simpler mode.

Share this post


Link to post
Share on other sites
Quote:
Original post by deadimp
How many elements are in the map when you run the second example?
Plus, try experimenting with a std::map without another map inside of it, just for testing purposes (in another project, of course). See if you get the same kind of error when running it in a simpler mode.


there are dynamic amount of elements.
but generally 12 elements.

okay, i'll run the tests.

Share this post


Link to post
Share on other sites
So here's the summary in simpler terms.

Error Type: Segmentation fault (core dumped) error.

No runtime error:
Total Cycles:10

for(int i=0; i<=10; i++){
skin.Read( "Body" );
}





Runtime error:
Total Cycles:4

std::map< std::string, std::map< std::string, std::string > >::iterator loop;
for ( loop=mainData.GetData().begin(); loop != mainData.GetData().end(); loop++ ){

skin.Read( "Body" );

}




No Runtime error:
Total Cycles:1

std::map< std::string, std::map< std::string, std::string > >::iterator loop;
for ( loop=mainData.GetData().begin(); loop != mainData.GetData().end(); loop++ ){

skin.Read( "Body" );
break;
}






//inside method skin.Read( const std::string );
std::cout << para_skinTypeValue.substr(0, para_skinTypeValue.find("($") );
para_skinTypeValue=para_skinTypeValue.substr(para_skinTypeValue.find("($")+2, para_skinTypeValue.length()-para_skinTypeValue.find("($")-2 );
EvaluateFunction( para_skinTypeValue.substr(0, para_skinTypeValue.find(")") ) );
para_skinTypeValue=para_skinTypeValue.substr(para_skinTypeValue.find(")")+1, para_skinTypeValue.length()-para_skinTypeValue.find(")")-1 );




and it seems like the
std::cout << para_skinTypeValue.substr(0, para_skinTypeValue.find("($") );
code is fine.
But the second line
para_skinTypeValue=para_skinTypeValue.substr(para_skinTypeValue.find("($")+2, para_skinTypeValue.length()-para_skinTypeValue.find("($")-2 );
causes the segmentation fault error when run twice inside the iterator. but doesn't create an error when run on a regular for loop.


Share this post


Link to post
Share on other sites
I don't see why you're iterating through a map at all.

Shouldn't you be using the iterator's pointed-to element to call Read()?

As it is, you're basically just using a std::map::iterator as a counting mechanism while continually acting on the same object. If for some reason this is intended behavior, you could still probably speed up the process by using the following instead:

for(int i = mainData.getData().size(); i > 0; i--)

Share this post


Link to post
Share on other sites
Quote:
Original post by Run_The_Shadows
I don't see why you're iterating through a map at all.

Shouldn't you be using the iterator's pointed-to element to call Read()?

As it is, you're basically just using a std::map::iterator as a counting mechanism while continually acting on the same object. If for some reason this is intended behavior, you could still probably speed up the process by using the following instead:

for(int i = mainData.getData().size(); i > 0; i--)


I'm sorry.
the actual code is this:


std::map< std::string, std::map< std::string, std::string > >::iterator loop;
for ( loop=mainData.GetData().begin(); loop != mainData.GetData().end(); loop++ ){

skin.Read( "Body", loop->second );

}



Difference:
loop->second

Reason:
To simplify debugging.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Try the following:


std::strinf str = "Body";
skin.Read( str );


Maybe there is some stupid optimization whereby the std::string constructed from the "Body" string is done only once instead of at every iteration. The above should clear this up for the compiler.

Share this post


Link to post
Share on other sites

int count=0;
std::string str="Body";
std::map< std::string, std::map< std::string, std::string > >::const_iterator loop;
for ( loop=mainData.GetData().begin(); loop != mainData.GetData().end(); loop++ ){
//std::cout << count;
//count++;

//std::cout << "(((((" << loop->first << ")))))";

skin.Read( str );
//if (count == 2 )
//break;
//skin.Read("Body", loop->second );
//print::Instance().SetData( loop->second );
//print::Instance().pData();
}



No luck.
Stil a Segmentation fault error.

Share this post


Link to post
Share on other sites
Quote:

segmentation fault n.

[Unix] 1. techspeak An error in which a running program attempts to access memory not allocated to it and core dumps with a segmentation violation error. This is often caused by improper usage of pointers in the source code, dereferencing a null pointer, or (in C) inadvertently using a non-pointer variable as a pointer. The classic example is:

int i;
scanf ("%d", i); /* should have used &i */


2. To lose a train of thought or a line of reasoning. Also uttered as an exclamation at the point of befuddlement.


@http://www.everything2.com/index.pl?node_id=41729

[Edited by - Run_The_Shadows on April 4, 2006 11:31:12 AM]

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
How about putting the assignement *inside* the loop? This way the 'str' variable will be reset to a fresh copy of "Body" at every iteration. Also, turn off optimizations.

Share this post


Link to post
Share on other sites
Try this:

if(loop->second)
skin.read("Body",loop->second);


The reason I'm suggesting this is because if you're getting pointer problems, it means somewhere about 4 cycles in, you're hitting a null pointer. It's hard to say for certain, since you continue to post incomplete versions of your code, but my hunch right now is that one of the values in your map is NULL.

Share this post


Link to post
Share on other sites
Quote:
Original post by Run_The_Shadows
Try this:

if(loop->second)
skin.read("Body",loop->second);


The reason I'm suggesting this is because if you're getting pointer problems, it means somewhere about 4 cycles in, you're hitting a null pointer. It's hard to say for certain, since you continue to post incomplete versions of your code, but my hunch right now is that one of the values in your map is NULL.


When I changed the iterator to
++loop
instead of
loop++

But to keep things to the bare minimum
I'm gonng run it as skin.read("Body")
b/c that doesn't run either.

I got rid of that particular error.
But I found another segmentation error. :(

[Edited by - Tradone on April 4, 2006 12:18:21 PM]

Share this post


Link to post
Share on other sites
Please help me.
I'm dying.

//main.cpp
for ( loop=mainData.GetData().begin(); loop != mainData.GetData().end(); ++loop ){
skin.Read("Body");

}

//Skin.cpp
void Skin::Read( std::string para_loadKey ){

/* */std::cout << "***************Inside Skin::Read******************";
std::cout << para_loadKey;
if( skinType.find( para_loadKey ) != skinType.end() ){
skinTypeValue = skinType[ para_loadKey ];
//std::cout << skinTypeValue;
//ParseLoops( skinTypeValue );
/* */std::cout << "***************ParseFunctions Enter******************";
ParseFunctions( skinTypeValue );
/* */std::cout << "***************ParseFunctions Exit******************";
}
/* */std::cout << "***************Exiting Skin::Read******************";
}
The Problem Method is ParseFunctions( string )

void Skin::ParseFunctions( std::string para_skinTypeValue ){
if ( TestingMode==2 )
std::cout << "ParseFunctions[[" << para_skinTypeValue << "]]";



while( para_skinTypeValue.find("($") != std::string::npos && para_skinTypeValue.find(")") != std::string::npos ){
if ( TestingMode==2 )
std::cout << "!W!\n";
//if ( truthTable.IfCheck() ){
if ( TestingMode==2 )
std::cout << "!C!\n";

//std::cout << para_skinTypeValue.substr(0, para_skinTypeValue.find("($") );
//para_skinTypeValue=para_skinTypeValue.substr(para_skinTypeValue.find("($")+2 );
//EvaluateFunction( para_skinTypeValue.substr(0, para_skinTypeValue.find(")") ) );
para_skinTypeValue=para_skinTypeValue.substr(para_skinTypeValue.find(")")+1 );
}
}


Share this post


Link to post
Share on other sites
Quote:
Original post by Tradone

para_skinTypeValue=para_skinTypeValue.substr(para_skinTypeValue.find(")")+1 );


What if ")" is the last character in the string?

Share this post


Link to post
Share on other sites
Quote:
Original post by Tradone
Please help me.
I'm dying.
*** Source Snippet Removed ***


I'm sorry, but your methodology isn't making much sense with the small snippets you're providing. I have a few questions:
1)What compiler are you using and does it have a debugger you can use?
2)Why are you still, in main, iterating through your map without actually having any interaction with that map?
3)is 'skin' a global object?
4)What do your stdout and stderr files look like?
5)From what I can tell, your skinTypeValue strings begin with "($" and end with ")"? If so, what's the logic in using .substr(")" + 1)? Wouldn't that make the new paraSkinTypeValue equal to the old paraSkinTypeValue's .end()?

Share this post


Link to post
Share on other sites
Quote:
Original post by Bregma
Quote:
Original post by Tradone

para_skinTypeValue=para_skinTypeValue.substr(para_skinTypeValue.find(")")+1 );


What if ")" is the last character in the string?


it could be the last string.
the input is absolutely dynamic.

Share this post


Link to post
Share on other sites
Quote:
Original post by Tradone
Quote:
Original post by Bregma
Quote:
Original post by Tradone

para_skinTypeValue=para_skinTypeValue.substr(para_skinTypeValue.find(")")+1);


What if ")" is the last character in the string?


it could be the last string.
the input is absolutely dynamic.


That's the point. It's like saying:

para_skinTypeValue=para_skinTypeValue.substr(para_skinTypeValue.end());


Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this