Jump to content
  • Advertisement
Sign in to follow this  
darkchrono4

malloc() problem

This topic is 4695 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I don't think anybody can help me with this as I don't think I can explain it properly. But maybe somebody has had a similar problem. Anytime I try and use malloc to get a memory block the program crashes with the unhelpful "program has caused an error, an errorlog is being generated" (which never is). The thing about this is it only gives me a problem if I include local header files (ie "include.h") if I use global includes (ie <stdio.>) I don't get a problem. The other thing is if I use the debug build then I don't get a problem. I also get this problem if I try and assign a pointer address from one variable to another. Tried playing with project settings in VS6 but nothing seems to be working. Anybody ever had anything like this? I should note that if I copy the needed functions used in the headers to the source file in question the problem goes away. You would think its something in one of the other files. But those are all part of a bigger project that uses malloc without a problem.

Share this post


Link to post
Share on other sites
Advertisement
You have a bug in your code. It has nothing to do with the headers you include.

In fact, when you say that it crashes when you assign a pointer to another, it seems to me as if there's some chance what you're actually doing is assigning pointed-at values through bad pointers.

To debug this problem, start the program in the debugger, and put a breakpoint in the code before the failing line. Run to the breakpoint. Then use single-step (F10 for step over, F11 for step in) and examine the various values before and after each line.

Share this post


Link to post
Share on other sites
One of the local include files had a #define for the malloc to use another function and the part of the program I'm working on didn't like. I just #undef then and my problem went away.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!