BUG: String.Format crashing when building very large Strings. [Pending fix]

Started by monkey0506, Mon 26/03/2007 17:18:54

Previous topic - Next topic

monkey0506

In the latest beta of my ScrollingDialog module, I note that there is an error which will cause the game to crash if you have a lot of dialog options (specifically with one or more long options). The line that was crashing the module was:

Code: ags
  this.__buffers[topicID] = String.Format("%s%d%s", this.__buffers[topicID].Substring(0, i), (state != false), this.__buffers[topicID].Substring(e, this.__buffers[topicID].Length));


The error being this:

Quote---------------------------
Illegal exception
---------------------------
An exception 0xC0000005 occured in ACWIN.EXE at EIP = 0x6974704F ; program pointer is -42, ACI version 2.72.920, gtags (2039,18)

AGS cannot continue, this exception was fatal. Please note down the numbers above, remember what you were doing at the time and notify CJ on the Tech forum.

in ScrollingDialog (line 363)
from ScrollingDialog (line 429)
from Global script (line 14)


Most versions of Windows allow you to press Ctrl+C now to copy this entire message to the clipboard for easy reporting.
---------------------------
OK   
---------------------------

The solution was simply not to use String.Format to build up the String. Using this instead fixed the problem:

Code: ags
  String __str = this.__buffers[topicID].Substring(0, i);
  __str = __str.Append(String.Format("%d", (state != false)));
  __str = __str.Append(this.__buffers[topicID].Substring(e, this.__buffers[topicID].Length));
  this.__buffers[topicID] = __str;


I know for a fact all the variables were valid, and it wasn't a normal "this is probably a scripting problem" error.

Just for reference, the exact text I was using:

Code: ags
// game start
  ScrollingDialog.SetText("new topic", 0, "this is some text");
  ScrollingDialog.SetText("new topic", 1, "this is some really longish text that I'm typing in here;;;;;;lolol look at those semi-colons aren't they great? XD hahahha jajja 111 lolz0rz I are the pwnt!");
  ScrollingDialog.SetText("new topic", 2, "this is some other text");
  ScrollingDialog.SetText("new topic", 3, "here's some more generic text");
  ScrollingDialog.SetText("new topic", 4, "a few more should do");
  ScrollingDialog.SetText("new topic", 5, "'cept I'm lazy, so this is it...");
  ScrollingDialog.SetText("new topic", 6, "d'oh! it wasn't enough");
  ScrollingDialog.SetText("new topic", 7, "this should help");
  ScrollingDialog.SetText("new topic", 9, "omfg");
  ScrollingDialog.SetText("new topic", 9, "omfg(2)");


Use that with the 2.0 Beta 1 and the game will crash. Commenting out the very last option serves as a partial fix, though not a very good one. And just a heads up, I realize there are two option 9s in the above example code, but that was actually a test of the module's "feature" by which if you try to add a new option in a non-sequential order it will automagically go to the first unused option (i.e., there's no option 8 so even though I put 9 it will be stored in option 8 ).

[EDIT:]

FRICKING SMILEY! :D

Pumaman

Do you have a sample game that uses the module? I've tried briefly to set something up but it'd be handy if you've got something that demonstrates the problem?

monkey0506

I don't actually have anything made up ATM, but I could come up with something shortly, upload, and edit this post when I'm done.

BTW, I thought that maybe it had something to do with trying to get a substring of the String that I was storing the new one into, but even when I tried storing it into a temporary variable (the long formatted String), it crashed on the line where I called String.Format which is how I determined what was causing the crash.

[EDIT:]

Crashing demo

Sure it's crap, but I threw it together in literally under 2 minutes. In fact in my test runs there were a lot of blue cups floating around for no recognizable reason...but it still displays the problem properly. I don't remember if I commented out the line or not, but in the global script you'll find the exact code I pasted above. If you just comment out the last line the game won't crash. Or if it is already commented out, uncomment it and it will crash.

Pumaman

Thanks. I've confirmed that String.Format crashes if the length of the resulting string is more than 1200 characters; I'll look into a fix.

monkey0506

Hahaha...stuff like this has got to make people wonder what the hell I'm doing. := 1200 character Strings...

Thanks for looking into this for me.

Shane 'ProgZmax' Stevens

QuoteScrollingDialog.SetText("new topic", 9, "omfg");
  ScrollingDialog.SetText("new topic", 9, "omfg(2)");

notice anything odd, here? :)  Not sure what if anything this has to do with your problem but I would say it's something to look at.

monkey0506

It's by design. Because the last option I added before that was option 7 the module will automatically convert any new indices greater than 8 to 8. It was a test of that feature.

Quote from: The part you didn't read Prog...And just a heads up, I realize there are two option 9s in the above example code, but that was actually a test of the module's "feature" by which if you try to add a new option in a non-sequential order it will automagically go to the first unused option (i.e., there's no option 8 so even though I put 9 it will be stored in option 8 ).

:)

Shane 'ProgZmax' Stevens


SMF spam blocked by CleanTalk