Re: Bug in my C++ program seems really strange. (Update on debugging
progress)
* mike3:
On Sep 1, 12:57 am, "Alf P. Steinbach" <al...@start.no> wrote:
* Gianni Mariani:
mike3 wrote:
On Aug 31, 10:32 pm, "Alf P. Steinbach" <al...@start.no> wrote:
...
http://www.mediafire.com/?cfmzd1y3yij
How does one build all that ?
Changes to make it /compile/:
fracalg\computefrac.cpp(371):#if 0 //APS
fracalg\computefrac.cpp(378):#endif //APS
fracalg\computefrac.cpp(393):#if 0 //APS
fracalg\computefrac.cpp(396):#else //APS
Excuse me, why all this? Those were commented
out for debugging purposes to help minimalize
the code.
I don't remember but I think you can figure it out. :-)
fracalg\computefrac.cpp(397): err = FG3DError(FG3D_INVALID_FRACTAL_TYPE,
FractalType); //APS
fracalg\computefrac.cpp(398):#endif //APS
This too.
This I think I remember. You called some fractal computation functions
that you didn't supply.
render\render.cpp(51): //APS MessageBox(NULL, TEXT("Zorg."),
TEXT(""), MB_OK);
render\render.cpp(69): //APS MessageBox(NULL, TEXT("Borg."),
TEXT(""), MB_OK);
Why couldn't it compile with those in?
Would compile but would not work, just silent termination. Don't set up
message loops in rendering. Btw., that has nothing to do with C++.
win32\CMainWnd.cpp(52): wcx.hCursor = LoadCursor(0,
IDC_ARROW); //APS LoadCursor((HANDLE)NULL, IDC_ARROW); /* cursor */
win32\fg3dImageWindow.cpp(34): wcx.hCursor =
LoadCursor(0,IDC_ARROW); //APS //LoadCursor((HANDLE)NULL, IDC_ARROW); /*
cursor */
win32\fg3dNewImageWzrd.cpp(18)://APS HWND gTmp;
win32\fg3dNewImageWzrd.cpp(32)://APS gTmp = hwndTmp;
main.h(108)://APS extern HWND gTmp;
fracgen3d.cpp(79):// APS
Plus, the WinMain function must be changed to something like
int WINAPI WinMain(HINSTANCE TheInstance, HINSTANCE LastInstance,
LPSTR lpszCmdLine, int iCmdShow)
{
__try
{
return cppWinMain( TheInstance, LastInstance, lpszCmdLine,
iCmdShow );
}
__except(TRUE)
{
TCHAR szBuf[256];
StringCchPrintf(szBuf, 256, TEXT("EXCEPTION %08lX"),
GetExceptionCode());
OutputDebugString(szBuf);
return 0;
}
}
where cppWinMain contains the original code for that __try.
It's funny (is that the right word?) when the code contains C style
casts that makes it not compile, when all that's needed is to remove
those casts...
I must be using a really crappy C++ compiler then as
it allows that stuff.
Yes. In addition it seem you're not using your compiler in the best
possible way. After upgrading to a better compiler, turn on all
standard-conformance and all warnings, make the thing compile cleanly.
So then it casts it automatically, you don't need all
that C-style stuff, then? Darn I'm too paranoid.
No, it's good to be paranoid in coding. But introducing casts is the
opposite of being paranoid: you're turning off all checks!
To be sufficiently paranoid you need to do the /opposite/: no casts.
Or at least as few as possible, and none in high-level code.
Having done all the above the program crashes on using an invalid
pointer txtrptr in [render.cpp] at line 62, which is due to using an
uninitialized member "d3dlr" (presumably there should have been an
earlier call to FractalImage::LockRectangle, but no such).
That is uninitialized? It calls LockRectangle() right
in there @ line 46.
I'm just reporting what it did. There was no actual call to that
function at run-time, before the crash. As to why that should happen,
well. :-)
Yes, I must be very bored to do such a thing! :-)
Cheers, & hth. (although I didn't look at the silly bignum class,
whatever its fault is, it may just be corrupted memory in general),
I've had a bear of a time trying to track it down.
General advice: in lots of places in the code there are checks whether
something is initialized or not.
If you instead make sure that constructors either initialize completely
and successfully, or else throw exceptions, you will only have properly
initialized objects around, and so you won't have to do that complicated
and leg-breaking dance.
Where it seems that you absolutely need some halfway initialized state,
like, calling a common Init function, consider replacing that Init
function with a proper constructor in a private base class (of course
this most often indicates a design issue, but better with a technical
fix than having that halfway initialized state causing general mess).
Cheers, & hth.,
- Alf
--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?