![]() |
|
Debug Assertion Failure! |
Onewing
Member #6,152
August 2005
![]() |
Here's another question for ya, while I'm waiting to figure out this one. Anyway, when I run my newest program (ChristmasHack title) as Debug, I get a Debug Assertion Failure when closing the program. This only occurs when my wrap text function is called (when talking to an NPC). If I run the program in Release, the problem doesn't exist. I reget doing this, but here's the text wrapping function. Keep in mind, I've done this entire game in the hack mindset, even long after CH finished.
------------ |
Kris Asick
Member #1,424
July 2001
|
I believe anywhere where you have the following fragments of code is bugged: (cSave, cParse + iIndex + 1) ...because the + operator is concatenating iIndex, check, 1 and 2 onto the cParse string when taking the length with strlen(), or when copying it to cSave with strcpy(), which I don't think is exactly what you're aiming for and I don't rightly know what will happen in memory when you do something like that. --- Kris Asick (Gemini) --- Kris Asick (Gemini) |
Onewing
Member #6,152
August 2005
![]() |
Quote: because the + operator is concatenating Since cParse is a pointer, I thought the + operator would move the address location of cParse. The output is exactly as I want, but when closing the program in Debug mode, it gives me that error. ------------ |
Kris Asick
Member #1,424
July 2001
|
Ah, you're right, it does move the pointer. Duh. Something doesn't feel right when I look at that code. I'll figure it out... EDIT: This might be causing the problem... iIndex = width / char_size - 1; // Find a space to break on while(iIndex > 0 && cParse[iIndex] != ' ') iIndex--; You see, width and char_size never change, so every time you start your loop you're checking iIndex number of characters beyond the current position within cParse, which may or may not be beyond the allocated memory for that variable. --- Kris Asick (Gemini) --- Kris Asick (Gemini) |
Onewing
Member #6,152
August 2005
![]() |
Quote: Something doesn't feel right when I look at that code.
Probably because it's dang fugly. Quote: You see, width and char_size never change, so every time you start your loop you're checking iIndex number of characters beyond the current position within cParse That shouldn't be the case. Because, while((strlen(cParse) - wrap_boundary) * char_size > width && line < 80) Thus, "iIndex = width / char_size - 1;" won't even occur unless "width / char_size" is within cParse's memory allocation. Does that make sense? This is probably an overcomplicated way of wrapping text. ------------ |
Kris Asick
Member #1,424
July 2001
|
Yeah, that makes sense... Well, I'm out of ideas. I suggest you try commenting the whole thing out, then slowly uncomment pieces of the code until the problem appears. Then you'll know where your memory leak is occurring, because it almost HAS to be a memory leak... The only other thing I can think of, but am not sure about, is that it might be related to your method of pointer movement with cSave and cParse. An assertion failure is a logic error where something that shouldn't happen does. Since you're not manually asserting anything it's something being handled automatically, which is almost certainly a memory issue. If the routine works properly with debugging off then I would say the problem has something to do with places you've used strcpy(), or with the way you're allocating and deallocating your pointers, and that it's related to stuff being left behind since the stuff that's actively being used by the routine is fine. --- Kris Asick (Gemini) --- Kris Asick (Gemini) |
|