errorLog = new Log("\\Log.html");
mmResource = new ResourceManager();
gemain = new GEMain();
ResourceManager::GetSingleton().addTextureResource("images\\test.bmp");
ResourceManager::GetSingleton().add3DSResource("model\\ship hull.3DS");
//test stuff
int test[100000];
🔒 Locked
Stack Overflow
Advertisement
Original Post
Hi, I am completely confused as to why I am getting a stack overflow. I have located the area/function that is causing the stack overflow, however I am not sure why it would be happening because it actually returns a value and moves on. Here is the main section of my program. Note I added the int test to make the stack over flow sooner than later. Since it was happening in a simple function. Now I get my stack overflow when it tries to create the test[100000]. However when I remove add3DSResource it works perfectly. So I can only assume that this is what is creating the problem (rihgt). Now for it to work properly I can only create a test of 7500. This leads me to beleive that this function os causing a stack overflow but I do not see how because arnt objects poped off that stack when they return. I would really appriciate some help with this problem!
EDIT: To make it a bit more clear the stack overflow was still happening in random places later on in the program so I added the int[100000] to make it happend eariler. So I could locate the problem easier.
No, that was not the problem, I just put the array there to make the overflow happen earlier. I used the array so I could make sure that the crate3dsModel was makeing the trouble (because as you can see, if you crusnch the numbers 100,000 - 7500 is like 92,500 * 32 bits (size of int)) so it seems like im loosing alost 400,000 bits or 400 kb from calling that function, and I am not sure why. Before I created the array, to see when the stack would overflow I added a few new functions which started to overflow. So I narrowed down the culprate to the Create3dsModel. So even if I didnt create a large array it would still eventually overflow.
I do not use any arrays in my program instead I use vectors and maps. So pretty much there is only 5 news called before the array is allocated and im sure the problem is in the Create3dsModel.
I will post the code to the create3dsModel
--SOURCE REMOVED
[Edited by - starfleetrp on August 18, 2006 6:46:48 PM]
No, that was not the problem, I just put the array there to make the overflow happen earlier. I used the array so I could make sure that the crate3dsModel was makeing the trouble (because as you can see, if you crusnch the numbers 100,000 - 7500 is like 92,500 * 32 bits (size of int)) so it seems like im loosing alost 400,000 bits or 400 kb from calling that function, and I am not sure why. Before I created the array, to see when the stack would overflow I added a few new functions which started to overflow. So I narrowed down the culprate to the Create3dsModel. So even if I didnt create a large array it would still eventually overflow.
I do not use any arrays in my program instead I use vectors and maps. So pretty much there is only 5 news called before the array is allocated and im sure the problem is in the Create3dsModel.
I will post the code to the create3dsModel
--SOURCE REMOVED
[Edited by - starfleetrp on August 18, 2006 6:46:48 PM]
Ok well as you can see for some reason Create3DSResource is eating up the whole stack because I could create an array of 100000 items no problem but after I called that function it is hard to even create an array 0f 7500. So I am just wondering why the heck it is causing this problem because I dont think im writing to the stack in Create3DSResource.
Repeating from other post: In my actual program the int test[100000] does not exist, it was just to see where the stack was being eaten up.
Repeating from other post: In my actual program the int test[100000] does not exist, it was just to see where the stack was being eaten up.
You can increase the default stack size in MSVC++ by adding this segement
to the linker argument section: /STACK:reserve[,commit]. Where commit is the new size in bytes. There are various advantages and disadvantage to this. Check
out this link: clicky
to the linker argument section: /STACK:reserve[,commit]. Where commit is the new size in bytes. There are various advantages and disadvantage to this. Check
out this link: clicky
I am not sure what you mean by "deep recursion" but here is the singleton class
[source lang = "cpp"]#pragma oncetemplate<typename T>class Singleton{ static T* ms_singleton; public: Singleton() { assert(!ms_singleton); //use a cunning trick to get the singleton pointing to the start of the whole, rather than //the start of the Singleton part of the object int offset = (int)(T*)1 - (int)(Singleton <T>*)(T*)1; ms_singleton = (T*)((int)this + offset); } ~Singleton() { assert(ms_singleton); ms_singleton=0; } static T& GetSingleton() { assert(ms_singleton); return *ms_singleton; } static T* GetSingletonPtr() { assert(ms_singleton); return ms_singleton; }};template <typename T> T* Singleton <T>::ms_singleton = 0;
Oops, sorry I just realised that I did not post the code. I do not think that it does, however I will post the code anyways incase I overlooked somethings.
-- CODE REMOVED
[Edited by - starfleetrp on August 18, 2006 6:41:36 PM]
-- CODE REMOVED
[Edited by - starfleetrp on August 18, 2006 6:41:36 PM]
Leave it up to an AP to be an asshole and off topic. The program, the log, and a resource manager are perfectly fine candidates for singletons for anyone but the most anal programmers. Not that it matters though, cuz his post isn't about getting feedback on his software architecture.
Quote:
Original post by DrEvil
ProcessNextChunk is recursing. Set a breakpoint in the top of it and see how deep it goes(how many layers of ProcessNextChunk pile up on the callstack) I'm guessing that's what is blowing the stack.
It goes two times.
Well without the int[7600] anything above 7500 will cause an immediate overflow once I have called the Create3DSResource. Well my program is basically Node->Entity._updateBounds()
The entity contains an
OBB* mOBB
so Entity::_updateBounds calls mOBB->UpdateBounds(orientation,scale,pos) note that this is the function that will overflow with my current setup. However if I do not load the model it does not overflow.
The entity contains an
OBB* mOBB
so Entity::_updateBounds calls mOBB->UpdateBounds(orientation,scale,pos) note that this is the function that will overflow with my current setup. However if I do not load the model it does not overflow.
void C3dsModel::ProcessNextChunk(_3DChunk *pPreviousChunk){ /* ... */ int buffer[50000] = {0}; /* ... */ case EDITOR_CHUNK: /* ... */ ProcessNextChunk(mCurrentChunk);}So you have recursion with a static array of 50000 itens, might be that. Might, I'm not bothering to check if it's called.
Quote:I'd say you're onto something there. That's nearly 200K for a single call of this function alone. It would be best to dynamically allocate that large array, or better yet, simply use a std::vector![cool]
Original post by vininim
*** Source Snippet Removed ***
So you have recursion with a static array of 50000 itens, might be that. Might, I'm not bothering to check if it's called.
To the OP, I'm not sure you understand that your int test[100000]; takes up space on the stack the moment that the function containing that definition is entered, NOT after the call to add3DResource. It does not matter where in the function you put that declaration as it always takes up space right from the beginning.
Topic Locked
This topic has been locked by a moderator. New replies are not allowed.
Sign in to reply to this topic.
Advertisement