Crystal Space
Welcome, Guest. Please login or register.
September 16, 2014, 08:47:02 pm

Login with username, password and session length
Search:     Advanced search
9018 Posts in 2051 Topics by 8464 Members
Latest Member: Imost
* Home Help Search Login Register
+  Crystal Space
|-+  Crystal Space Development
| |-+  Support
| | |-+  Problem with Push function in csStringArray
« previous next »
Pages: [1] Print
Author Topic: Problem with Push function in csStringArray  (Read 3176 times)
eventhorizon5
Jr. Member
**
Posts: 53


View Profile WWW
« on: June 01, 2006, 05:34:34 am »

Hi

I'm having some trouble with csStringArray's Push function.  My app has a data file loader (LoadDataFile function) that simply loads a text file into a string array using the Push function.  The first 7 lines of the test file get loaded properly, but all lines from 8 on are empty (has something to do with the length of line 8 which causes some error).

Here's the first 8 lines of the test file:
Code:
#MyBuilding

<Globals>
    Name = My Building
    Designer = Me
    CameraAltitude = 3.2
    ElevatorShafts = 1
    Floors = 9 #10 total floors/levels, 0 to 9
(file is here: http://www.tliquest.net/cgi-bin/viewcvs.cgi/skyscraper-c%2B%2B/buildings/Simple.bld?rev=1.1&view=markup)

and here's part of the app's code (full file is here: http://www.tliquest.net/cgi-bin/viewcvs.cgi/skyscraper-c%2B%2B/src/fileio.cpp?rev=1.9&view=markup - it's at the bottom of the file)
Code:
//loads a building data file into the runtime buffer
bool streamnotfinished = true;
char buffer[1000];

...

csFileReadHelper file_r(file);

...

//read each line into the buffer
streamnotfinished = file_r.GetString(buffer, 1000, true);

//push buffer onto the tail end of the BuildingData array
BuildingData.Push(buffer);

Main info:
CS 2006-05-19 cvs snapshot built on VC8 Express, with winlibs r21; Windows 2000, AMD Athlon XP.

Thanks

-eventhorizon

Logged
schorsch_76
Newbie
*
Posts: 7


View Profile
« Reply #1 on: June 01, 2006, 12:32:37 pm »

You clear the buffer with spaces, i think if you clear your buffer with \0 (ascii code zero) this with solve your problem. Because most string fuction determine the end of a C-string at the ending "0".

Bye

schorsch
Logged
jorrit
Administrator
Hero Member
*****
Posts: 1706


View Profile
« Reply #2 on: June 01, 2006, 12:42:35 pm »

You clear the buffer with spaces, i think if you clear your buffer with \0 (ascii code zero) this with solve your problem. Because most string fuction determine the end of a C-string at the ending "0".

Bye

schorsch

That shouldn't matter in this case since GetString() is supposed to ignore the contents of that buffer anyway. We're still investigating why it is wrong.

Greetings,
Logged
res
Develazyoper
CS Developer
Full Member
*****
Posts: 206


View Profile Email
« Reply #3 on: June 01, 2006, 03:24:08 pm »

Though clearing with spaces is unusual, I don't see anything glaringly obviously wrong. Perhaps just single-step through the code to find where exactly the data gets wrong...
Logged
eventhorizon5
Jr. Member
**
Posts: 53


View Profile WWW
« Reply #4 on: June 01, 2006, 10:03:15 pm »

Though clearing with spaces is unusual, I don't see anything glaringly obviously wrong. Perhaps just single-step through the code to find where exactly the data gets wrong...

I've already done that - I'm currently using VC 2005 Express (this app will be transferred over to Linux later on), and I traced through all the internal CS functions that were called, and suprisingly the data element was added correctly with the memcpy function, but it and all subsequent elements are all empty.  I've got some screenshots of the debugging so you can see what's going on.  In the last pic (6), I created a csString called 'a', and tested the csStringArray's Top() function by dumping the contents into 'a' (the string array is called BuildingData, and is supposed to hold the contents of the entire data file for the script parser function (LoadBuilding) to use).

Pics are here:
http://www.tliquest.net/skyscraper/1.1/problem/

-eventhorizon

Logged
res
Develazyoper
CS Developer
Full Member
*****
Posts: 206


View Profile Email
« Reply #5 on: June 01, 2006, 10:09:42 pm »

In the last pic (6), I created a csString called 'a', and tested the csStringArray's Top() function by dumping the contents into 'a' (the string array is called BuildingData, and is supposed to hold the contents of the entire data file for the script parser function (LoadBuilding) to use).

Don't just look at a.minibuff. This is an internal buffer used for small strings (by default strings taking up to 36 chars w/ null). For longer strings, the 'Data' member will be used, you need to check if _that_ has the correct value.
Logged
res
Develazyoper
CS Developer
Full Member
*****
Posts: 206


View Profile Email
« Reply #6 on: June 01, 2006, 10:11:45 pm »

You could also trace into the assignment of a. (While I personally doubt that you'll find a bug there, you'll gain more understanding of how csString stores data internally.)
Logged
eventhorizon5
Jr. Member
**
Posts: 53


View Profile WWW
« Reply #7 on: June 01, 2006, 10:16:48 pm »

Quote

Don't just look at a.minibuff. This is an internal buffer used for small strings (by default strings taking up to 36 chars w/ null). For longer strings, the 'Data' member will be used, you need to check if _that_ has the correct value.
Quote

Just checked that, and I'm about to do a full trace - the Data member has a null pointer after "a = BuildingData.Top();".

-eventhorizon
Logged
res
Develazyoper
CS Developer
Full Member
*****
Posts: 206


View Profile Email
« Reply #8 on: June 01, 2006, 10:22:03 pm »

Just checked that, and I'm about to do a full trace - the Data member has a null pointer after "a = BuildingData.Top();".

That could really be a bug in csString then... on the last shot, the value returned by Top() has clearly the expected string pointer.
Logged
eventhorizon5
Jr. Member
**
Posts: 53


View Profile WWW
« Reply #9 on: June 01, 2006, 10:28:09 pm »

Quote

Don't just look at a.minibuff. This is an internal buffer used for small strings (by default strings taking up to 36 chars w/ null). For longer strings, the 'Data' member will be used, you need to check if _that_ has the correct value.

Correction to my last post - I checked the wrong file input string.
It's properly returning the stuff in the Data member, and that was what I wasn't noticing before (so it's my fault lol).  I was just tracing the code and watching the minibuff value.

-eventhorizon
« Last Edit: June 01, 2006, 10:30:10 pm by eventhorizon5 » Logged
Pages: [1] Print 
« previous next »
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.2 | SMF © 2006-2007, Simple Machines LLC Valid XHTML 1.0! Valid CSS!
Page created in 7.202 seconds with 16 queries.