Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Windows / weird exception when loading many terrains

Author
Message
sovr
14
Years of Service
User Offline
Joined: 2nd Jan 2010
Location: USA
Posted: 7th Jan 2013 01:30
Hello, I have a nice software that makes large scale terrains and slices the terrain up into many object files. Within the object files name it says "terrain_x0y0.obj" the x0 and y0 represents where that piece of the terrain goes. I made a chunk of code that would load part of the terrain, but each time I get an exception from it.

I narrowed it down to do something with the tr LPSTR string and when ever I try to default what tr represents like tr = " "; it will give me an exception. When I take out the tr = " "; it will run longer, but the string gets too big and runs into another exception (file size I am guessing). I thank anyone who can help me on this problem, and here is the code:



hello there!
Ancient Lady
Valued Member
20
Years of Service
User Offline
Joined: 17th Mar 2004
Location: Anchorage, Alaska, USA
Posted: 7th Jan 2013 03:11
In Tier 2, it is up to you to clear the memory allocated by the agk::Str command. It does not get cleared automatically when the variable goes out of scope. This will cause a memory leak.

You need to do use 'delete[] varname' to properly clean up memory allocated by agk::String.

Also, it is a good idea to move your variable definitions ('LPSTR j = agk::Str(h);') outside of the loops. It will take up less memory and be faster processing. Declare the variables before the loop and then just assign them within the loop.

And, the following code shows you how to avoid dealing with all of these issues using sprintf.


Cheers,
Ancient Lady
AGK Community Tester and AppGameKit Master
sovr
14
Years of Service
User Offline
Joined: 2nd Jan 2010
Location: USA
Posted: 7th Jan 2013 03:32
Thank you very much it works just fine and no exceptions! I sort of forgot about the delete function in C++... it has been a while, lol.

hello there!
Ancient Lady
Valued Member
20
Years of Service
User Offline
Joined: 17th Mar 2004
Location: Anchorage, Alaska, USA
Posted: 7th Jan 2013 16:27
Always glad to help.

Happy Programming!

Cheers,
Ancient Lady
AGK Community Tester and AppGameKit Master

Login to post a reply

Server time is: 2024-03-28 21:26:38
Your offset time is: 2024-03-28 21:26:38