Crystal Space
Welcome,
Guest
. Please
login
or
register
.
May 24, 2013, 12:37:39 pm
1 Hour
1 Day
1 Week
1 Month
Forever
Login with username, password and session length
Search:
Advanced search
9224
Posts in
2230
Topics by
5388
Members
Latest Member:
ryankbyers
Crystal Space
Crystal Space Development
Support
Problem with Push function in csStringArray
« previous
next »
Pages:
[
1
]
Author
Topic: Problem with Push function in csStringArray (Read 2930 times)
eventhorizon5
Jr. Member
Posts: 53
Problem with Push function in csStringArray
«
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
Re: Problem with Push function in csStringArray
«
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: 1703
Re: Problem with Push function in csStringArray
«
Reply #2 on:
June 01, 2006, 12:42:35 pm »
Quote from: schorsch_76 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
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
Re: Problem with Push function in csStringArray
«
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
Re: Problem with Push function in csStringArray
«
Reply #4 on:
June 01, 2006, 10:03:15 pm »
Quote from: res 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...
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
Re: Problem with Push function in csStringArray
«
Reply #5 on:
June 01, 2006, 10:09:42 pm »
Quote from: eventhorizon5 on June 01, 2006, 10:03:15 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
Re: Problem with Push function in csStringArray
«
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
Re: Problem with Push function in csStringArray
«
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
Re: Problem with Push function in csStringArray
«
Reply #8 on:
June 01, 2006, 10:22:03 pm »
Quote from: eventhorizon5 on June 01, 2006, 10:16:48 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
Re: Problem with Push function in csStringArray
«
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
]
« previous
next »
Jump to:
Please select a destination:
-----------------------------
Crystal Space Development
-----------------------------
=> General Crystal Space Discussion
=> Support
-----------------------------
Crystal Space Project Development
-----------------------------
=> Feature Requests
=> Plugins
=> Bug Reports
-----------------------------
Crystal Space Development
-----------------------------
=> Game Content Creation
-----------------------------
Miscellaneous
-----------------------------
=> Article/Tutorial Requests
=> Article/Tutorial Discussion
-----------------------------
Crystal Space Project Development
-----------------------------
=> Development Discussion
-----------------------------
Crystal Space Projects
-----------------------------
=> Project Discussion
=> WIP Projects
=> Finished Projects
-----------------------------
Associate Projects
-----------------------------
=> CEL Discussion
=> Crystal Core Discussion
=> CrystalBlend Discussion
-----------------------------
Crystal Space Project Development
-----------------------------
=> Google Summer of Code
-----------------------------
Associate Projects
-----------------------------
=> Apricot (Open Game)
=> Ares Project
Loading...