循环不起作用,硬编码 [英] Loop Does'nt Work, Hard code does

查看:82
本文介绍了循环不起作用,硬编码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个函数,它根据从文件中读取的数字创建一个指向未签名的

整数数组的指针。然后我继续从文件中读取文件名

,将名称转换为char *并使用它从一些外部函数加载纹理

。我的问题在于for循环,代码

如下。


//我创建了指针数组,我是使用2只是为了一个

的例子

MapTextures = new unsigned int [2];


//启动for循环

for(int I = 0; I< 2; I ++)

{//然后我从文件中读取文件名。

LevelStream>> Cmd;

//将我读取的字符串转换为字符*

Name = strdup(Cmd.c_str());

//使用文件名将coorisponding图像加载到数组上的第一个

元素

MapTextures [i] = LoadTextureWithAlpha(Name);

}


这就是我想要的方式,但出于某种原因,它确实无法工作,而且对于我的生活我只需要
我不明白为什么。当代码执行时,它会读取两个文件名并将它们转换得很好,但它只会加载一个

纹理。我在排除故障时尝试了以下代码,它完美地工作了




LevelStream>> Cmd;

Name = strdup(Cmd.c_str());

MapTextures [0] = LoadTextureWithAlpha(Name);

LevelStream> > Cmd;

Name = strdup(Cmd.c_str());

MapTextures [1] = LoadTextureWithAlpha(Name);

这种方式是因为它涉及硬编码一定数量,所以我更喜欢这个,而我实际上真的想知道为什么涉及for循环的方法。只会

加载一个纹理。鉴于这段代码有效,对我而言,
意味着我在for循环中遇到的问题。是因为它是
是一个for循环而不是其中的函数。

是否与在

正在编译?或者我只是遗漏了一些明显的东西?

谢谢

尼克

I''m working on a function which creates a pointers to an array of unsigned
ints based off a number read from a file. I then continue to read file names
from the file, convert the name to a char* and use it to load an texture
from some outside functions. My problem lies in the "for loop", the Code
goes as follows.

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

//Start up a for loop
for(int I = 0; I < 2; I++)
{ //I then read the filename from the file.
LevelStream >> Cmd;
//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 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);
This way is''nt preferable because it involves hardcoding a set amount, and I
really really want to know why the method involving the "for loop" will only
load the one texture. Given that this peice of code works it would, to me,
imply that the problem I''m having in the "for loop" lies in the fact that it
is a for loop and not the functions within.
Does it have something to do with the way a for loop is handled after
being compiled? Or am I just missing something obvious?
Thanks
Nick

推荐答案

>这种方式不是优选的,因为它涉及硬编码一定量,并且
> This way is''nt preferable because it involves hardcoding a set amount, and
I
我真的非常想知道为什么涉及for循环的方法。将
仅加载一个纹理。鉴于这段代码有效,对我来说,它意味着我在for循环中遇到的问题。是因为
它是for循环而不是其中的函数。
它是否与编译后处理for循环的方式有关?或者我只是遗漏了一些明显的东西?
really really want to know why the method involving the "for loop" will only load the one texture. Given that this peice of code works it would, to me,
imply that the problem I''m having in the "for loop" lies in the fact that it is a for loop and not the functions within.
Does it have something to do with the way a for loop is handled after
being compiled? Or am I just missing something obvious?




可能错误在你的LoadTextureWithAlpha函数中。您是否尝试使用调试器来查找问题?


Niels Dybdahl



Probably the error is in your LoadTextureWithAlpha function. Have you tried
using a debugger to find the problem ?

Niels Dybdahl


可能错误发生在LoadTextureWithAlpha函数中。你有没有
尝试使用调试器来查找问题?
Probably the error is in your LoadTextureWithAlpha function. Have you tried using a debugger to find the problem ?




没有错误,在Borland Builder 5和Visual Studio 6之间我没有得到

文件加载方面的单个错误。另外,当连续硬编码版本正常工作时,循环如何影响

Textre加载?


Nick



No Errors, Between Borland Builder 5 and Visual Studio 6 I''m not getting a
single error in the file loading aspect. Also, how would the loop affect the
Textre loading when the Consecutive hardcode version works fine?

Nick



" Nick L" <铁******** @ mchsi.com>在消息中写道

新闻:ElVYc.263740

"Nick L" <Fe********@mchsi.com> wrote in message
news:ElVYc.263740


这篇关于循环不起作用,硬编码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆