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 26 2007, 04:42 AM
Post
#2
|
|
![]() 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
#3
|
|
|
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). |
|
|
|
Capn_Fish Another C++ Issue Nov 21 2007, 04:28 PM
koan I don't know so much about exception processin... Nov 22 2007, 01:05 AM
Snappy You may also want to put it some debug output stat... Nov 22 2007, 06:36 AM
Capn_Fish I don't call clear anywhere. What other functi... Nov 22 2007, 08:06 AM
Snappy A quick look .. could it be something to do with h... Nov 22 2007, 09:20 AM
koan QUOTE(Snappy @ Nov 22 2007, 09:20 AM) A q... Nov 25 2007, 10:08 PM
Capn_Fish Sure, I'll go put some cout'd numbers in n... Nov 22 2007, 09:49 AM
koan QUOTE(Capn_Fish @ Nov 22 2007, 09:49 AM) ... Nov 23 2007, 01:26 AM
koan Hi
I decided to look at your code. I don't us... Nov 25 2007, 11:55 PM
Snappy QUOTE(Capn_Fish @ Nov 23 2007, 01:49 AM) ... Nov 25 2007, 09:19 AM
Snappy Just curious ...
mapp.cpp, line 147
QUOTEchar Li... Nov 25 2007, 09:36 AM
Snappy btw, if you wish, you can also include the functio... Nov 25 2007, 09:50 AM![]() ![]() |
|
Lo-Fi Version | Time is now: 23rd May 2013 - 02:28 PM |