![]() ![]() |
Nov 21 2007, 04:28 PM
Post
#1
|
|
![]() Group: Members Posts: 2,350 Joined: 30-July 06 Member No.: 10,575 |
I'm getting an error:
CODE terminate called after throwing an instance of 'std::ios_base::failure' what(): basic_ios::clear Aborted With my latest C++/SDL app. What causes this, and what can I do about it? It works fine on my laptop, but when I try to run it on my Z, I got the above error. Any help would be much appreciated. |
|
|
|
Nov 22 2007, 01:05 AM
Post
#2
|
|
|
Group: Members Posts: 318 Joined: 25-February 04 From: UK Member No.: 2,025 |
I don't know so much about exception processing or lowlevel ios stuff, so this is a bit of a guess. The code is clearing a stream and setting some flags; the flags being set aren't supported by the Z C++ RTL. I would grep the code for "clear(" and look for an iostream. You'll need to change the parameters to clear(), probably some weird default that doesn't really matter or something new that isn't supported by the Z RTL. Don't know about the what(); maybe it's the what() function that is calling clear() ? Another thing to grep for. |
|
|
|
Nov 22 2007, 06:36 AM
Post
#3
|
|
|
Group: Members Posts: 793 Joined: 28-November 04 From: NM, US, sometimes Asia Member No.: 5,633 |
You may also want to put it some debug output statements and do a trace.
btw, was there a coredump? From your output, don't seem to have one. You could potentially trace the faulty statement with the dump. |
|
|
|
Nov 22 2007, 08:06 AM
Post
#4
|
|
![]() Group: Members Posts: 2,350 Joined: 30-July 06 Member No.: 10,575 |
I don't call clear anywhere. What other functions call it?
Thanks for the help. EDIT: Here's my backup tarball from yesterday, if anybody would care to look at it.
Attached File(s)
|
|
|
|
Nov 22 2007, 09:20 AM
Post
#5
|
|
|
Group: Members Posts: 793 Joined: 28-November 04 From: NM, US, sometimes Asia Member No.: 5,633 |
A quick look .. could it be something to do with http://opensource.adobe.com/gil/html/group..._e_g___i_o.html
"Throws std::ios_base::failure if none of the types in Images are compatible with the type on disk. " EDIT: btw, can you put in debug output messages in your main so that you know where this error is coming from? Will be helpful for me to human-trace your code as I don't have linux dev setup. |
|
|
|
Nov 22 2007, 09:49 AM
Post
#6
|
|
![]() Group: Members Posts: 2,350 Joined: 30-July 06 Member No.: 10,575 |
Sure, I'll go put some cout'd numbers in now.
EDIT: Attached source EDIT2: It's failing between 4 & 5, or in the "ReadMap" function: EDIT3: Now, after making NO changes other than adding in some debug output, it's just segfaulting ( I should really stop posting these types of issues at night when everything looks hopeless... Thanks again for your help! EDIT4: Yup, I got it (one too few characters in my array. Funny that it worked on the laptop...). I'll leave the source up as a teaser.
Attached File(s)
|
|
|
|
Nov 23 2007, 01:26 AM
Post
#7
|
|
|
Group: Members Posts: 318 Joined: 25-February 04 From: UK Member No.: 2,025 |
EDIT3: Now, after making NO changes other than adding in some debug output, it's just segfaulting When the behaviour of the program changes after making such slight changes that's a clear indication of reading/writing to illegal memory. You should have run valgrind on the program when compiled on your desktop to make sure there are no obvious errors, it would have caught the problem and told you where it was. |
|
|
|
Nov 25 2007, 09:19 AM
Post
#8
|
|
|
Group: Members Posts: 793 Joined: 28-November 04 From: NM, US, sometimes Asia Member No.: 5,633 |
Sure, I'll go put some cout'd numbers in now. EDIT: Attached source EDIT2: It's failing between 4 & 5, or in the "ReadMap" function: EDIT3: Now, after making NO changes other than adding in some debug output, it's just segfaulting ( I should really stop posting these types of issues at night when everything looks hopeless... Thanks again for your help! EDIT4: Yup, I got it (one too few characters in my array. Funny that it worked on the laptop...). I'll leave the source up as a teaser. Something came up ... checking it out. Might be awhile, 'cos I'm outta town for 2 weeks ... sorry! EDIT3: Now, after making NO changes other than adding in some debug output, it's just segfaulting When the behaviour of the program changes after making such slight changes that's a clear indication of reading/writing to illegal memory. You should have run valgrind on the program when compiled on your desktop to make sure there are no obvious errors, it would have caught the problem and told you where it was. Aye ... sounds like a pointer problem or something ... |
|
|
|
Nov 25 2007, 09:36 AM
Post
#9
|
|
|
Group: Members Posts: 793 Joined: 28-November 04 From: NM, US, sometimes Asia Member No.: 5,633 |
Just curious ...
mapp.cpp, line 147 QUOTE char Line[60]; MapIn.open("../maps/test.map"); for(int y = 0; y < 15; y++) { MapIn.getline(Line,61); Should 61 MapIn.getline(Line, 61) be 60 instead? This might be causing an overflow or write pass buffer error, which can/will cause corruption if the byte past Line[59] is code or something vital. http://www.cplusplus.com/reference/iostrea...am/getline.html Have not read the other code yet, but this could be a place to start perhaps. |
|
|
|
Nov 25 2007, 09:50 AM
Post
#10
|
|
|
Group: Members Posts: 793 Joined: 28-November 04 From: NM, US, sometimes Asia Member No.: 5,633 |
btw, if you wish, you can also include the functions GetLevelFromMap, ReadMap and SetTiles can be included as functions in the Tile class, since they seem to mainly manipulate the tiles. Well, but that's software architecture ... I digress ... hehe
Anyway, in case if you wish to have some classing done for your app, let me know, I happen to have a 'fetish' for doing classing etc ... |
|
|
|
Nov 25 2007, 10:08 PM
Post
#11
|
|
|
Group: Members Posts: 318 Joined: 25-February 04 From: UK Member No.: 2,025 |
A quick look .. could it be something to do with http://opensource.adobe.com/gil/html/group..._e_g___i_o.html "Throws std::ios_base::failure if none of the types in Images are compatible with the type on disk. " Fish isn't using Adobe's Generic Image Library. This link is irrelevant. |
|
|
|
Nov 25 2007, 11:55 PM
Post
#12
|
|
|
Group: Members Posts: 318 Joined: 25-February 04 From: UK Member No.: 2,025 |
Hi
I decided to look at your code. I don't usually develop for SDL and my local Linux mirror is unavailable so I can't install the header files at the moment. Anyway, first some tips: 1. If you want to add debug output, use cerr. cout is buffered, so the program may have continued further than the output when it stopped but the buffer was not cleared. 2. Instead of outputting "1", "2" etc, add cerr << "SetUpDisplay() start\n" and cerr << "SetUpDisplay() end\n" at the start and end of your functions. It's much easier to see what failed. 3. stringtochar You obviously haven't heard of std::string::c_str(). Example: char *mycharstar; std::string mystring("Hello"); mycharstar = mystring.c_str(); 4. Go easy on the global variables! A good C++ design rarely needs them. 5. Add comments in your header files, explain what a function is *supposed* to do. When I have the SDL include files I'll be able to compile and do some debugging. |
|
|
|
Nov 26 2007, 04:42 AM
Post
#13
|
|
![]() Group: Members Posts: 2,350 Joined: 30-July 06 Member No.: 10,575 |
Thanks for the helpful comments! I love open-source for this reason, that I can just stick my code here with an issue, and somebody will find other things that are wrong with it and point me to them.
1. Never heard of cerr, I'll look into it. 2. Same as #1. 3. Haven't heard of that either. I'll look into it too. 4. I was thinking if I used some globals that would be used commonly, I could sacrifice a tiny bit of RAM to gain some speed from not having to create and destroy them so often. Misconception? 5. I don't usually do that (I never expect anybody else to look at my code), but I actually have comments in this stuff. I'm slowly adding more as I work on different sections. Thanks a lot (Just note that much of the code posted has been replaced as I am in the process of changing methods for moving the character about). |
|
|
|
Nov 27 2007, 05:12 PM
Post
#14
|
|
|
Group: Members Posts: 318 Joined: 25-February 04 From: UK Member No.: 2,025 |
4. I was thinking if I used some globals that would be used commonly, I could sacrifice a tiny bit of RAM to gain some speed from not having to create and destroy them so often. Misconception? Yes. Making the variable global pollutes the name space, any savings are insignificant. Say for example you have a map class with public members width and height. All you need is a reference to the map object and you can access these variables. If you keep a pointer to the map object then you spend an extra 32/64 bits to store the memory address and there might be 1 extra look up (go to map object, access member). Hardly a huge cost. QUOTE 5. I don't usually do that (I never expect anybody else to look at my code), but I actually have comments in this stuff. I'm slowly adding more as I work on different sections. It's design methodology. When you come back to that code to add something or hunt down some bug you'll be looking at a function and trying to work out if it's correct or not. Before I write any functions I write the class definition and comments on what the functions are supposed to do. Some other comments: In input.cpp: CODE bool eXit = false; This kind of variable naming is asking for trouble. In map.cpp CODE const int TileSize = 32; this is also not good: you have hard coded a global variable and the value is only accessible in a specific source file. In screen.hpp: CODE const int screenWidth = 640; //Hardcoded for the Zaurus const int screenHeight = 480; //Hardcoded for the Zaurus You should #define this in some global configuration and #include it here. Then, when you want to recompile for another platform you can just change these variables. In map.cpp: CODE if(tens == '0' or tens == '1' or tens == '2' or tens == '3' or tens == '4' or tens == '5' or tens == '6' or tens == '7' or tens == '8' or tens == '9') { if(tens == '0') { intTens = 0; } etc Very ouch! Some comments on the layout: Why don't you have a map class ? Likewise a screen class ? It would group together related functions and variables, improve the readability of your code Why is CanMove() not a member of Character class ? If you make an enumerated type for direction, then you can have code like myCharacter.Move(NORTH) which is a lot easier to read than myCharacter.Move(2). |
|
|
|
![]() ![]() |
|
Lo-Fi Version | Time is now: 25th May 2013 - 02:23 AM |