Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Draw Missing!?  (Read 35098 times)

0 Members and 1 Guest are viewing this topic.

qsik

  • Jr. Member
  • **
  • Posts: 60
    • View Profile
Draw Missing!?
« Reply #30 on: August 11, 2008, 07:48:40 am »
this is odd, for some reason, images dont load for the questions and answers arrays even though they do for the other arrays...is my syntax wrong?

Code: [Select]
int LoadImages()
{
for(int begin = 0, finish = 6, place = 1; begin < finish; begin++, place++)
{
std::string base = "C:/Jeopardy/";
std::string end = ".png";
std::string middle;
std::string image;
middle = Convert(place);
image = base + "Other/Slide" + middle + end;
if (!other[begin].LoadFromFile(image))
return EXIT_FAILURE;
};

for(int begin = 0, finish = 6, place = 1; begin < finish; begin++, place++)
{
std::string base = "C:/Jeopardy/";
std::string end = ".png";
std::string middle;
std::string image;
middle = Convert(place);
image = base + "Categories/Slide" + middle + end;
if (!categories[begin].LoadFromFile(image))
return EXIT_FAILURE;
};

for(int begin = 0, finish = 5, place = 1; begin < finish; begin++, place++)
{
std::string base = "C:/Jeopardy/";
std::string end = ".png";
std::string middle;
std::string image;
middle = Convert(place);
image = base + "Money/Slide" + middle + end;
if (!money[begin].LoadFromFile(image))
return EXIT_FAILURE;
};

for(int begin = 0, finish = 30, place = 1; begin < finish; begin++, place++)
{
std::string base = "C:/Jeopardy/";
std::string end = ".png";
std::string middle;
std::string image;
middle = Convert(place);
image = base + "Questions/Slide" + middle + end;
if (!questions[begin].LoadFromFile(image))
return EXIT_FAILURE;
};

for(int begin = 0, finish = 30, place = 1; begin < finish; begin++, place++)
{
std::string base = "C:/Jeopardy/";
std::string end = ".png";
std::string middle;
std::string image;
middle = Convert(place);
image = base + "Answers/Slide" + middle + end;
if (!answers[begin].LoadFromFile(image))
return EXIT_FAILURE;
};

return EXIT_SUCCESS;
}

qsik

  • Jr. Member
  • **
  • Posts: 60
    • View Profile
Draw Missing!?
« Reply #31 on: August 13, 2008, 06:32:59 am »
a little help plz?

*posting cause ive had so many edits, i dont know if the message of a new post shows up

quasius

  • Full Member
  • ***
  • Posts: 166
    • View Profile
Draw Missing!?
« Reply #32 on: August 13, 2008, 07:02:21 am »
Quote from: "qsik"
a little help plz?

*posting cause ive had so many edits, i dont know if the message of a new post shows up


Since you never answered the first time...  Have you stepped through that part of the code with a debugger, watching all relevant variables to make sure it's doing what you think it is?

qsik

  • Jr. Member
  • **
  • Posts: 60
    • View Profile
Draw Missing!?
« Reply #33 on: August 13, 2008, 07:13:19 am »
i looked at the sf::Image questions/answers arrays and in the questions, only 3 images load while none load in the answers array

--the VC++ debugger cant seem to check variables unless they're global and also, since i have many functions wrapped up into a single load function, i cant find exactly whats going wrong...only something is wrong with my LoadImages()

--could u also help me with figuring out how to convert TCHARS into a std::string?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Draw Missing!?
« Reply #34 on: August 13, 2008, 09:51:40 am »
Quote
--the VC++ debugger cant seem to check variables unless they're global

Make sure you're executing a debug build with debug informations generated.
You can also search for some debugger tutorials, after all this is the most powerful tool you'll ever use as a programer ;)

Quote
could u also help me with figuring out how to convert TCHARS into a std::string?

If you're building in unicode mode, TCHAR* is an array of wide chars, and you'll need functions like std::ctype::narrow or wstombs to convert.
If you're not in unicode mode, TCHAR* is a regular array of char and the conversion is automatic.
But where do you get your TCHARs from ?
Laurent Gomila - SFML developer

qsik

  • Jr. Member
  • **
  • Posts: 60
    • View Profile
Draw Missing!?
« Reply #35 on: August 13, 2008, 04:30:49 pm »
ok, thnx for the info

im using unicode and trying to use GetModuleFileName(), which only takes TCHARS when using unicode otherwise i get a conversion error

--i read up on wstombs but i didnt really get how to use it

*could u check to see if my for loop syntax is correct? some of the images in the last two for loops are not loading for some reason

quasius

  • Full Member
  • ***
  • Posts: 166
    • View Profile
Draw Missing!?
« Reply #36 on: August 13, 2008, 05:22:49 pm »
Quote from: "qsik"

*could u check to see if my for loop syntax is correct? some of the images in the last two for loops are not loading for some reason


Did you get the debugger working?
I'm really not trying to be an ass here, but you absolutely must learn to use a debugger if you have any plans of being a programmer.  I'd much rather point you to tools to help yourself than just debugging your code and posting fixes.  I've been programming for 10+ years first as a hobby and then professionally and I still make "syntax errors" all the time.  But the debugger is the efficient tool for finding and eliminating those errors without anyone else's help.
In fact, if I were to fix your code, I'd c/p it into an IDE and use the debuggger.  But that wouldn't really help you much beyond the immediate problem.

Edit:  Your for loops, while possibly correct, are *extremely* non-standard and needlessly complex.  I'd look there first for problems.
It's rare to need a for loop not of the form:

for (unsigned int i = 0; i < nFinish; i++)
{
     .....
}

Then just index off of i.  If you want to start at a different index, just init i to something other than 0.  It's extremely rare to need multiple init statements as you are doing.  I've probably done than once or twice in the last year.
Also returning stuff like EXIT_SUCCESS and EXIT_FAILURE from functions is non-standard.  That's generally used for the main function only.  You can do it, but it looks strange and you'll probably get asked about it at some point.
In your case, it probably just makes sense to return a bool and return false on an error and true otherwise.
If you want an "error code" system, you should probably define stuff other than EXIT_SUCCESS and EXIT_FAILURE.

qsik

  • Jr. Member
  • **
  • Posts: 60
    • View Profile
Draw Missing!?
« Reply #37 on: August 13, 2008, 06:55:53 pm »
thnx for the advice, ill take it to heart

i do have it in an IDE, VC 2008 express, but im not very good with the debugger

--im just a C++ newbie coming from calculator BASIC

quasius

  • Full Member
  • ***
  • Posts: 166
    • View Profile
Draw Missing!?
« Reply #38 on: August 13, 2008, 07:09:00 pm »
Quote from: "qsik"
thnx for the advice, ill take it to heart

i do have it in an IDE, VC 2008 express, but im not very good with the debugger

--im just a C++ newbie coming from calculator BASIC


That's fine.  Calculator BASIC was some of my first programming too.  Check the stuff that Laurent suggested a couple of posts ago and read something like this: http://www.cs.uvm.edu/~upe/resources/debugging/visualStudioCDebug/

The debugger is not actually that complicated, but it's extremely powerful.

qsik

  • Jr. Member
  • **
  • Posts: 60
    • View Profile
Draw Missing!?
« Reply #39 on: August 13, 2008, 09:29:37 pm »
very odd, this for loop breaks out after 5 iterations...even though it should run 30 times right?
Code: [Select]

int LoadImages3()
{
for(int i = 0; i < 30; i++)
{
middle = Convert((i + 1));
image = base + "Questions/Slide" + middle + end;
if (!questions[i].LoadFromFile(image))
return -1;
image = base + "Answers/Slide" + middle + end;
if (!answers[i].LoadFromFile(image))
return -1;
};

return 1;
}

zac

  • Jr. Member
  • **
  • Posts: 60
    • View Profile
Draw Missing!?
« Reply #40 on: August 13, 2008, 09:47:42 pm »
For unicode support, most of the Windows API Functions have a "W" version (W like Wide Character)... Just use "GetModuleFileNameExW"... it should take 16-bit WCHAR strings as arguments...

quasius

  • Full Member
  • ***
  • Posts: 166
    • View Profile
Draw Missing!?
« Reply #41 on: August 13, 2008, 09:57:30 pm »
Quote from: "qsik"
very odd, this for loop breaks out after 5 iterations...even though it should run 30 times right?
Code: [Select]

int LoadImages3()
{
for(int i = 0; i < 30; i++)
{
middle = Convert((i + 1));
image = base + "Questions/Slide" + middle + end;
if (!questions[i].LoadFromFile(image))
return -1;
image = base + "Answers/Slide" + middle + end;
if (!answers[i].LoadFromFile(image))
return -1;
};

return 1;
}


It should, unless it errors out of one of your LoadFromFile calls and hits a return -1.  You can step through the loop (keep hitting f10 in the debugger) or place breakpoints at bother of those return -1 lines to see if and where that's happening.

Avency

  • Full Member
  • ***
  • Posts: 113
    • View Profile
Draw Missing!?
« Reply #42 on: August 13, 2008, 09:58:23 pm »
If it fails to load an image, the function will return. Check your console output (or whatever you redirected cerr to). Maybe the problem is a broken image file.

qsik

  • Jr. Member
  • **
  • Posts: 60
    • View Profile
Draw Missing!?
« Reply #43 on: August 14, 2008, 01:00:47 am »
this is strange, the loop goes through 3 times and then on the 4th loop, questions[4] cant seem to load C:/Jeopardy/Questions/Slide5.png (but the image load fine in GIMP and so the loop breaks (does lack of memory also cause images to not load?)

--using GetModuleFileNameExW i get an identifier not found?

quasius

  • Full Member
  • ***
  • Posts: 166
    • View Profile
Draw Missing!?
« Reply #44 on: August 14, 2008, 03:34:24 am »
Quote from: "qsik"
this is strange, the loop goes through 3 times and then on the 4th loop, questions[4] cant seem to load C:/Jeopardy/Questions/Slide5.png (but the image load fine in GIMP and so the loop breaks (does lack of memory also cause images to not load?)

--using GetModuleFileNameExW i get an identifier not found?


I've had some issues with random .pngs not loading.  There is some type of .png setting SOIL seems to not like.  Try openeing in GIMP or whatever and resaving as a new file.  (This should clean up whatever weird header irregularities are causing problems.  I've had no trouble loading .pngs exported from GIMP.)

Edit:  Lack of memory could certainly cause a failure depending on how SOIL handles such situations, but I can't image that's the problem.  Do you have any reason to believe you're consuming all your system's memory?

 

anything