Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » Strange MV C++ error in dev-c++..

This thread is locked; no one can reply to it. rss feed Print
Strange MV C++ error in dev-c++..
Albin Engström
Member #8,110
December 2006
avatar

Ok, im still working on my "write a string with my bitmaps function" but when i got too the part where i was going to use the string.at(pos) function, i get a strange error saying:

Runtime Error!
Program:

This application has requested the Runtime to terminate it in an unusual way.
Please contact the application's support team for more information...

first: this error was kinda unexpected since i really followd how to use strings.. but i guess i did not follow the instuctions too well, as i never do.
any idea on what might be the cause of this very intimidating problem?..

second: WHAT SUPPORT TEAM?? how do i change this? becouse i don't like it when my app says things for me.. and this error was an microsoft visual c++ error.... where did that came from? the string library?

here's the code.

noc = text.txt[txtstring].length();
for(nr1=noc; nr1>0; nr1--)
{
if(text.txt[1].at(1)==' ')<< this is the top of the cream.. or whathever you call it.. if i remove this, it'l work.
bax++;
}

Elverion
Member #6,239
September 2005
avatar

Would it kill you to use capitalization, spell check, and code tags?

noc = text.txt[txtstring].length();
for(nr1 = noc; nr1 > 0; nr1--)
{
  if( text.txt[txtstring].at(1) == ' ' )
    bax++;
}

It looks like you were using txtstring's length for whatever was in position 1 in text.txt, which may or may not have existed. I'm not sure if that was supposed to be like that or not without more code, but to me, it looked like an error.

--
SolarStrike Software - MicroMacro home - Automation software.

Albin Engström
Member #8,110
December 2006
avatar

No, not really, but i don't know how too use code tags (because i did not care about it). but i will probably use it in the future.

the txtstring is a value i use to get a string from text.txt[]
text is struct.
txt[] is as you may have guessed, an string array.

if( text.txt[txtstring].at(1) == ' ' ) should actually be if( text.txt[txtstring].at(nr1) == ' ' ) but it does not matter in this case.(i guess?).

i'm sorry that i can't give you more code, i've seen other people posting there codes and they end up having corrections for everything but the problem they was asking about ^^'.. so i minimize this possibility by not posting my whole code.
besides, I'm very embarrassed by showing of my code, it's worse that going around nude on the street...

Elverion
Member #6,239
September 2005
avatar

Hmm, well, I can understand why some people (especially new programmers) are embarrassed to show their messy code, but it is for the best. It is better to get those conventions down now while you are still learning, rather than struggle with them later on.

What exactly are you trying to do? Just count the number of spaces in a string?

unsigned int SpacesInString(std::string input)
{
  unsigned int count = 0;
  for(unsigned int i = 0; i < input.length(); i++)
  {
    if( input<i> == ' ' )
      count++;
  }

  return count;
}

Then just call bax = SpacesInString( text.txt[txtstring] ). You get the idea at least. I think it is easier, and more logical, to read the characters from 0 to length, but if you prefer to do it the opposite way, that's fine too.

--
SolarStrike Software - MicroMacro home - Automation software.

Albin Engström
Member #8,110
December 2006
avatar

:), Sorry if i have confused you with my bad explanation of what I'm trying to do, i will try to give you a more detailed description.

i have a function called "write" to which i send the folling data,
1:the bufferbitmap.
2:the string i want too use in form of a number, taken from an array of strings.
3:the X and Y value of the leftupper corner of where the text should be displayed.
4:the hight and width of the box, in which the string will be displayed.

this function then draws the string(WILL draw), within the box.

void write(BITMAP *b, int txtstring, int posX, int posY, int hight, int width)
{
to give the text display a nice look i decided to make an extra piece of code,
instead of drawing it character by character
i would have it check if rendering a word on the current row would have it
displayed outside the box, so before drawing the word it would check if it
would have gone outside the boundaries(wait, wasn't that what i said?).

anyway:

as i'm new to almost everything out there i always test things before using
them for real, therefor i wrote this:

if(text.txt[txtstring].at(1) == ' ')
bax++;

the only thing i was hoping for was a valid code, but that strange error showed
up and now i'm stuck on that part. well, in a few days i will begin to study
c++ in school 8-). beginning with the A course (we will probably talk about
things even i know about). i think my problem will be solved at that time, but
i don't want to wait, cause i hate to wait.

besides, this microsoft visual c++ thing really scares the shit out of me..
i hate microsoft... and i really don't want an microsoft stained application..
what should i do!? help me!!
}

(i did not use code tags again, because i don't think of that as code..)

BAF
Member #2,981
December 2002
avatar

Quote:

i'm sorry that i can't give you more code, i've seen other people posting there codes and they end up having corrections for everything but the problem they was asking about ^^'.. so i minimize this possibility by not posting my whole code.
besides, I'm very embarrassed by showing of my code, it's worse that going around nude on the street...

Well, our corrections are to help show you potential bad practices or flaws in your code. You really shouldn't be embarrassed about your code.

Quote:

besides, this microsoft visual c++ thing really scares the shit out of me..
i hate microsoft... and i really don't want an microsoft stained application..
what should i do!? help me!!

What? What the hell are you talking about... what is a microsft stained application?

As far as helping you with this problem, I don't really get what the problem is and what you are doing and why you are doing it. :-/

Albin Engström
Member #8,110
December 2006
avatar

Well, mainly, i'm not experienced enought to take in everything everyone says, therefor i try to avoid advanced talk...

personally i think i described pretty well what im trying to do :(.

I'm trying to make a function for drawing text on the screen, THE END. :P.

ok, i freaked out when my app made the word "microsoft". i don't expect you too understand my feelings :'(..

i've added an attachment, it's a picture of armageddon.

BAF
Member #2,981
December 2002
avatar

That's just because you are using the MS runtime (which you can't really avoid on Windows) and your program is crashing.

As far as drawing text, what's wrong with textprintf_ex or textout_ex?

Elverion
Member #6,239
September 2005
avatar

Also, shouldn't '' be '\0' for the NULL character (I think that's what you were checking for)? I don't understand why you would want to do that though...it would occur at whatever length() returns.

Exactly how does putting text onto the screen relate to the code you've shown? I guess you are trying to use these strings to format it in some way, but I don't see how it relates to your code. Can you give us an example of what one of these strings should look like, and how you would like it to be used (in code)?

--
SolarStrike Software - MicroMacro home - Automation software.

Albin Engström
Member #8,110
December 2006
avatar

:), as i said, the code i wrote was only written as a test, it has nothing to do with writing a string on the screen, but i'm glad that i did not write it because i can't use the .at() string command.

Do i have to use the MS runtime? :/

are you saying that ' ' is the same thing as ''? and that '\0' is for the NULL character? (is that the blankspace?).
in that case it would seem logical that checking for '' would cause an error.. i'm going to test this.

It seems that was not the case, as it still does not work. :(

LennyLen
Member #5,313
December 2004
avatar

Quote:

Do i have to use the MS runtime?

On MS Windows, yes.

Quote:

are you saying that ' ' is the same thing as ''? and that '\0' is for the NULL character?

' ' is not the same as ''. ' ' is the blankspace character. '' is an empty character constant. You should get compiler errors if you try to use ''.

Yes, '\0' is the NULL character.

Tomasz Grajewski
Member #4,284
February 2004

Quote:

to give the text display a nice look i decided to make an extra piece of code,
instead of drawing it character by character
i would have it check if rendering a word on the current row would have it
displayed outside the box, so before drawing the word it would check if it
would have gone outside the boundaries(wait, wasn't that what i said?).

I think, that You are talking about word wrapping. I'm right? If yes, then I have a such function, which prints text to a bitmap with word wrapping (and if it isn't possible, then with character wrapping). I hope that it will be useful to You :)

1#include <allegro.h>
2#include <allegro/internal/aintern.h>
3 
4 
5//...
6 
7 
8int textout_wrapped(BITMAP *dest, const FONT *my_font, const char *text, int x1, int y1, int x2, int line_height, int fore_color, int back_color)
9{
10 ASSERT(dest);
11 ASSERT(my_font);
12 ASSERT(text);
13 
14 int x = x1;
15 int y = y1;
16 int c;
17 int word_w = 0;
18 const char *word_start = text;
19 bool first_word = true;
20 
21 while ((c = ugetxc(&text)))
22 {
23 int nc = ugetc(text);
24 
25 if ((c != '\n') && (c != ' '))
26 word_w += my_font->vtable->char_length(my_font, c);
27 
28 if (!nc || (c == ' ' && nc != ' ') || (c != ' ' && nc == '\n') || (c == '\n' && nc != '\n'))
29 {
30 if (!first_word && (x + word_w > x2))
31 {
32 #ifdef DEBUGMODE
33 my_font->vtable->render_char(my_font, '>', makecol(0, 255, 0), back_color, dest, x, y);
34 #endif
35 
36 y += line_height;
37 x = x1;
38 }
39 
40 first_word = false;
41 word_w = 0;
42 
43 bool first_space = true;
44 while ((word_start != text) && (c = ugetxc(&word_start)))
45 {
46 if (c == '\n')
47 {
48 #ifdef DEBUGMODE
49 my_font->vtable->render_char(my_font, '>', makecol(255, 0, 0), back_color, dest, x, y);
50 #endif
51 
52 y += line_height;
53 x = x1;
54 first_word = true;
55 }
56 else
57 {
58 if ((c == ' ') && first_space)
59 first_space = false;
60 else if (x + my_font->vtable->char_length(my_font, c) > x2)
61 {
62 #ifdef DEBUGMODE
63 my_font->vtable->render_char(my_font, '>', makecol(0, 0, 255), back_color, dest, x, y);
64 #endif
65 
66 y += line_height;
67 x = x1;
68 first_word = false;
69 }
70 
71 if ((c == ' ') && first_space)
72 first_space = false;
73 
74 x += my_font->vtable->render_char(my_font, c, fore_color, back_color, dest, x, y);
75 }
76 }
77 }
78 }
79 
80 #ifdef DEBUGMODE
81 /*
82 ** Draws the number of text lines printed.
83 */
84 textprintf_ex(dest, my_font, x, y, makecol(255, 255, 0), back_color, "%i", (y - y1 + line_height) / line_height);
85 #endif
86 
87 /*
88 ** Returns the height of the text printed with word wrapping.
89 */
90 return y - y1 + line_height;
91}

___________________________________________________________________________________________
mBlocks - a Tetris clone written in JavaScript | Merix Studio - website design & development | Zeitgeist

Albin Engström
Member #8,110
December 2006
avatar

LennyLen: Noted.

Tomasz Grajewski: I don't use fonts, i use bitmaps. but thanks anyway :).

BAF
Member #2,981
December 2002
avatar

What? WHY don't you use fonts?

Albin Engström
Member #8,110
December 2006
avatar

Because fonts don't look as good as bitmaps. :).

LennyLen
Member #5,313
December 2004
avatar

Quote:

Because fonts don't look as good as bitmaps.

So create a font from your bitmaps then.

Thomas Fjellstrom
Member #476
June 2000
avatar

Not sure if you're aware Albin, but allegro's fonts support bitmapped true colour "fonts". As well as the normal mono fonts.

--
Thomas Fjellstrom - [website] - [email] - [Allegro Wiki] - [Allegro TODO]
"If you can't think of a better solution, don't try to make a better solution." -- weapon_S
"The less evidence we have for what we believe is certain, the more violently we defend beliefs against those who don't agree" -- https://twitter.com/neiltyson/status/592870205409353730

Albin Engström
Member #8,110
December 2006
avatar

... you're kidding, right? ><. That's so annoying.. but good, so how do i use this feature?

Thomas Fjellstrom
Member #476
June 2000
avatar

You create a image with the font characters you want, and import via the grabber as a FONT object, then you load the created datafile when you load your program, and theres your font.

--
Thomas Fjellstrom - [website] - [email] - [Allegro Wiki] - [Allegro TODO]
"If you can't think of a better solution, don't try to make a better solution." -- weapon_S
"The less evidence we have for what we believe is certain, the more violently we defend beliefs against those who don't agree" -- https://twitter.com/neiltyson/status/592870205409353730

Albin Engström
Member #8,110
December 2006
avatar

Nice, but isn't there like a guide line for how i should put the bitmaps(in the bitmap) in order to get a valid font?

Go to: