Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Loop Does'nt Work, Hard code does

Reply
Thread Tools

Loop Does'nt Work, Hard code does

 
 
Jerry Coffin
Guest
Posts: n/a
 
      08-31-2004
"Nick L" <(E-Mail Removed)> wrote in message news:<86VYc.263646$eM2.249913@attbi_s51>...

[ ... ]

> //I create the array of pointers, I'm using 2 just for the sake of an
> example
> MapTextures = new unsigned int[2];


There have been quite a few comments, but I haven't seen any mention
of the error here: your comment says this is an arry of pointers, but
in fact it's an array of unsigned shorts. If the function does what it
seems to imply, this is almost certainly a major problem (unless
you've transcribed your code and made a typo).

> //Start up a for loop
> for(int I = 0; I < 2; I++)
> { //I then read the filename from the file.
> LevelStream >> Cmd;


Unless you're sure your filename will never contain any white space
characters, using an extraction operator to get it is probably a poor
idea.

> //Convert the string I read to a char*
> Name = strdup (Cmd.c_str());
> //Use the filename to load the coorisponding image into the first
> element on the array
> MapTextures[I] = LoadTextureWithAlpha(Name);


This doesn't look very good to me. First of all, LoadTextureWithAlpha
should really accept a string (or reference to a string) as its
parameter, rather than requiring a char *. Second, even if there's
good reason to pass it a pointer to char, there shouldn't be a problem
with just using:

LoadTextureWithAlpha(Cmd.s_str());

This passes a pointer to const char, but LoadTextureWithAlpha really
shouldn't be modifying its parameter.

> This is the way I'd like to do it, but for some reason it does'nt work and
> for the life of me I can't figure out why. When the code executes it will
> read both file names and convert them just fine, but it will only load one
> texture. The following code I tried while I was troubleshooting and it works
> perfectly.
>
> LevelStream >> Cmd;
> Name = strdup (Cmd.c_str());
> MapTextures[0] = LoadTextureWithAlpha(Name);
> LevelStream >> Cmd;
> Name = strdup (Cmd.c_str());
> MapTextures[1] = LoadTextureWithAlpha(Name);


My guess is that you still have the same problem, but something
inconsequential has changed that happens to hid the problem.

--
Later,
Jerry.

The universe is a figment of its own imagination.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Triple nested loop python (While loop insde of for loop inside ofwhile loop) Isaac Won Python 9 03-04-2013 10:08 AM
Getting a loop to activate a loop above it Byte Python 4 03-24-2006 03:04 AM
Condition outside loop or separate loop for different condition? - Java 12 06-15-2005 08:50 AM
while loop in a while loop Steven Java 5 03-30-2005 09:19 PM
Loop the loop... =?Utf-8?B?VGltOjouLg==?= ASP .Net 2 02-16-2005 12:21 PM



Advertisments