Stack Overflow

Started by
29 comments, last by vininim 17 years, 8 months ago
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.

	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];

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!
Advertisement
Don't create arrays of that size on the stack

// badint test[100000]; // goodint* test = new int[100000]; // use testdelete [] test;// betterboost::scoped_array<int> test(new int[100000]);
daerid@gmail.com

Yeah, your little "Test" takes like 400k out of the stack and that's a bit too much, considering that stack size could be like 1MB by default.

Cheers !
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]
let's see 100000 ints is roughly 390 KB. default stack size if i recall right is 1 MB... should work... does add3DResource create a lot on the stack as well?

EDIT: Wow, 3 posts added as I typed this lol.
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.
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
Don't do that. That's fixing the symptoms not the actual problem. That should only be an option if you know what is blowing the stack, and are sure its not a bug and you need to do it. Are you using deep recursion in your application? That's the easiest way to blow the stack.
Let's see that singleton class
daerid@gmail.com
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;

This topic is closed to new replies.

Advertisement