The working path is different between direct runs and runs from within the IDE. Have you considered that the file simply might not be found? In other words, have you checked the return value of fopen?
The working path is different between direct runs and runs from within the IDE. Have you considered that the file simply might not be found? In other words, have you checked the return value of fopen?
All the buzzt!
CornedBee
"There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
- Flon's Law
It finds the file, and it reads it correctly. But it still crashes. Oh and the release version crashes on dummy3 the debug version crashes on the next "new".
This line should be OK, if temp is of type int.Originally Posted by The Wazaa
Unless your system is running out of memory, you're just seeing another symptom of your original problem.Originally Posted by The Wazaa
I would bet that the real problem is in code executed even earlier than this code.
As a rough rule, there are only two things that can make operator new "go crazy": running out of memory (in which case an bad_alloc exception will be thrown and caught). If that's not the case, then your most likely offender is code that executed somewhere before the "crazy" behaviour became apparent.
The fact that this "new works" means nothing. A problem has occurred earlier, and you need to find the cause of that.Originally Posted by The Wazaa
As a rough rule, the symptoms of a problem cannot occur before the cause.
This is just a second symptom of your underlying problem. Which, I repeat, will be in code executed before this fragment.Originally Posted by The Wazaa
You are mistaken in your assessment that the "file is correct since it works in debuggers".Originally Posted by The Wazaa
Code working correctly in debuggers, but not in production, is a symptom of a serious problem in your code (unless you have encountered a problem in the debugger or compiler: that is possible, but highly unlikely in your case).
The place you need to look is in code that is executed before the latest snippet you've given.
Since the problem could be anywhere (as grumpy said), you need to basically post the whole code for people to get a good look at all the things which could be going wrong.
If the project is still pretty small, then post it 'as is'.
If it's large, then you need to produce a smaller runnable example which still shows the problem.
a) make a backup / clone of the project
b) remove code which hasn't run yet.
c) experiment with commenting out code which has run, but which doesn't change the crash.
Hopefully, when you've done that, you'll have a much smaller (and easier for us to examine) example program to diagnose.
Often, just doing this will lead you to the answer you seek, as you eliminate possibilities.
Luckily this was almost in the beginning of the whole project. A window is created before it, but I switched the location of that initialisation so it is created after but the program still crashes.
This is all the code that runs before the crash, and a bit after it:
Thanks for all your repliesCode:// Check below
The Wazaa
Last edited by The Wazaa; 03-06-2006 at 12:33 PM.
I don't exactly see what these two lines are trying to accomplish:
In both cases, temp is the size of the buffer that you are using memset on, which means you are most likely writing past the bounds of your array.Code:memset(models[i].fileName+temp, 0, strlen(models[i].fileName) - temp); //... memset(worldFileName+temp, 0, strlen(worldFileName) - temp);
"Think not but that I know these things; or think
I know them not: not therefore am I short
Of knowing what I ought."
-John Milton, Paradise Regained (1671)
"Work hard and it might happen."
-XSquared
Well, of some strange reason my strings get longer than I want, so I simply writes over the memory after it. Are you sure this causes the error? I thought that memset did not care about whether it writes outside the boundry of an array. And, if the length of the string would be as big as I wanted, it would not overwrite anything so I don't think that it is the problem. Its just an ugly way to solve that a lot of wierd characters seem to get into my string
Thanks for your reply
The Wazaa
You should never write outside the bounds of your array (unless you're writing a buffer overflow exploit)
If your strings don't hold the data you expect to see, then it's a sign that there is something else wrong in your code (in readStr maybe?)
"Think not but that I know these things; or think
I know them not: not therefore am I short
Of knowing what I ought."
-John Milton, Paradise Regained (1671)
"Work hard and it might happen."
-XSquared
Oh, I think I forgot to post readStr. And the characters that I speak about is in the string from the moment I create it. Check above for the readStr function.
But that is weird the way it runs from within the compiler. Maybe the working directories are set up wrong. With my compiler, my program always works when run inside the compiler, because the compiler sets the right working directories, but it usually crashes when I run the actual exectuable because it can't find the file that I'm trying to load.
> memset(models[i].fileName+temp, 0, strlen(models[i].fileName) - temp);
If you want a \0 terminator, just do
models[i].fileName[temp] = '\0';
Your strlen() assumes there is a \0 there to begin with, and if it's not there you end up with v.large values of strlen(), resulting in very large values of memory being cleared.
I could have sworn I asked you to post something which compiles and runs, yet you just posted random snippets all the same.
If you don't post full compilable code to such problems, expect half-assed answers and guesses in response.
It works now
It actually was the strings, which I have been trying to get Null-terminated before in the right way but nothing worked. Thanks a lot to everyone who posted here
The GL engine http://e43.sag.karlstad.se/it18/Skicka.zip if you want to see it
The Wazaa
~* Old post *~
Sorry, I've been breaking my whole program down now and only the needed code is included, at least I think so
And here is a the complete source:
EDIT: removed
That is all code I have and it runs perfect in the debugger but the exe crashes.
Thanks for your replies
The Wazaa
Last edited by The Wazaa; 03-06-2006 at 01:27 PM.