I am currently writing a game rendering engine using LWJGL 3 and Kotlin. Everything works fine for multiple minutes, until out of nowhere the program exits with the following message:
Process finished with exit code -1073740940 (0xC0000374)
All I do is load a few models, and then render them with glDrawElements(...) in the main loop - nothing else is loaded or changed.
Now, I know that this error code means heap corruption, but I do not even get a hs_err_pid logfile and the Java Debugger just crashes with the program. So how would I go about debugging such a crash? Could this be because of an incompatibility with Kotlin?
So, for everyone who may find themselves in a similar situation: Thanks to the LWJGLX debug tool by Kai Burjack, I instantly found what crashed the program.
What I did was the following: In the shader class, when uploading a matrix, I allocated a managed FloatBuffer, which I then accidentally tried to free manually:
val buf = BufferUtils.createFloatBuffer(16)
matrix.get(buf)
glUniformMatrix4fv(location, false, buf)
MemoryUtil.memFree(buf)
The MemoryUtil.memFree() call actually doesn't crash, but as the matrix changes every frame, this method corrupts the heap over time - hence the crash after a few minutes.
I attached the LWJGLX debugger and now my program crashed instantly - with a precise error message telling me that I am trying to free a Memory Region i did not allocate with memAlloc() - So after changing my code to
val buf = MemoryUtil.memAllocFloat(16)
...
MemoryUtil.memFree(buf)
everything now works. I can only recommend the LWGLX debugger - It also found some memory leaks I now have to fix ;-)
Related
I have written a objective-c wifi library and a c wrapper around it to call from my c++ code using corewlan framework.I have setup timers and on expiry of the timer i call scanwifi function of the library which gives details of all the wifi network details.The program keeps crashing by giving malloc error incorrect check sum for freed object. The crash is not consistent,keeps appearing a random places. I tried guard malloc to find the memory bug, left the program running for more than 10 hours but it didn't crash. as soon as i removed guard malloc and executed the program and boom there was the crash. Can anyone please tell ways to catch this memory bug
Thanks
Memory management errors can be particularly difficult to track down; without seeing code it's hard to say.
You mentioned GuardMalloc—have you tried enabling other Diagnostics?
Scribble
Guard Edges
Guard Malloc
Zombie Objects
This can help debugging by making your code crash more predictably—hopefully closer to the source of the error.
(In Xcode 4.4.1, these are set via "Product"->"Edit scheme"->"Run"->"Diagnostics".)
My iOS app is randomly crashing but I don't get any warning/error in the console. I think it might be a memory leak but shouldn't I receive a EXC_BAD_ACCESS error at least ?
The other thing might be a memory overloading, but I don't get any memory warning and I've just tested the app with the instruments tool.
So why does it crash without printing anything in the console ?
Thanks
UPDATE:
I'm actually getting a memory warning in the instruments although I don't see the memory to increase. COuld be the cause of the crash ? How do i know where is the memory warning generated ? (See screenshot: )
Tell your program to print a backtrace every time it receives a low memory warning.
From Apple documentation:
UIKit provides several ways to receive low-memory notifications, including the following:
Implement the applicationDidReceiveMemoryWarning: method of your
application delegate.
Override the didReceiveMemoryWarning method in
your custom UIViewController subclass.
Register to receive the
UIApplicationDidReceiveMemoryWarningNotification notification.
Enable Zombie objects and try again. https://stackoverflow.com/a/8050701/1271579
Edit: If the device runs out of memory, you will recieve a few memory warnings before crashing so you should probably optimize it.
I'm currently working on a game for iPhone/iPad using Cocos2D.
On the simulator it works fine and can run for hours, without any problems.
But on a device, it runs for some time and then just crashes out of nowhere. The debug console gives no error message, typing in "bt" just returns "No stack." and it doesn't generate a crash report.
It mostly crashes when loading the main menu or a new level but it can happen while playing a level as well.
Any ideas on how to debug this?
You should really read about memory management in objective-c
https://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/MemoryMgmt/Articles/MemoryMgmt.html
When I first switched to programming in objective-c (from C#/Java background), I had a lot of problems too. Once I understood memory management in objective-c, I rarely have those kind of problems. I don't use arc.
Whenever you alloc & init an object, the retain count is 1. You should remember to release these objects at some point. If you use other methods, then you get an autorelease object. That is the convention.
The time you will save is really worth it.
I am using Garbage collector in my Cocoa based application on Mac OS X. It has 100s of threads running and synchronization is done using Operation Queue.
After a long run, one of the object is garbaged and application will crash.
Checking to see if the object is non nil also fails as the the object is invalid and contains some garbage value. Calling a method on the object leads to crash.
Anyone please help me in debugging the issue.
Thank you......................
I am using Garbage collector in my
Cocoa based application on Mac OS X.
It has 100s of threads running and
synchronization is done using
Operation Queue.
More likely than not, the bug lies within the seemingly rather overly concurrent nature of your code. Running 100s of threads on a machine with "only" double digits worth of cores (if that) is unlikely to be very efficient and, of course, keeping everything properly in sync is going to be rather difficult.
The best place to start is to turn on Malloc stack logging and use malloc_history to find out what events occurred at the address that went south.
Also, there were fixes in 10.6.5 that impacted GC correctness.
If you can change the code of the garbage collected object, then override the finalize method like this, to get some information:
- (void) finalize
{
NSLog(#"Finalizing!\n%#", [[NSThread callStackSymbols] componentsJoinedByString:#"\n"]);
//if you put here a breakpoint, you can check the supposed references to this object
[super finalize];
}
I'm getting some really strange errors in XCode. Whenever I run my program, I get:
malloc: test_node_integrity: FreeListNode 0x1052af0 { _prev =
0xffffffff, _next = 0xffffffff, _size = 0 } failed integrity check.
I've searched all over Google, but haven't found anyone else with this error message. The stack trace has methods that aren't in my program - it's some other thread that XCode is running. Is there anyway I could get more information on this? I've already tried uninstalling/reinstalling XCode (10.5.8, XCode 3.1).
I am using Garbage Collection, so I'm wondering if there is an error there. I used to be getting a different error, "missing cpu_capibilites.h," which would point to a string formatting method. The error changed into one with the debugger not being able to roll back the state, and now I have this error.
If there's any other error information that I should have posted, let me know.
What's happening is that something in your program or a framework it uses is writing into unused memory (the Garbage Collection heap) and destroying internal data structures in the unused memory. The next time something asks AutoZone (the GC memory allocator) to allocate memory, it tries to read the structures in unallocated memory, finds them to be invalid, and throws the above message.
You can read the source that's doing this at http://www.opensource.apple.com/source/autozone/autozone-77.1/AutoAdmin.cpp?f=text
So you need to look for memory smashers.
If this is related to NSOpenPanel being used in conjunction with GC, I think it may be a known problem. See this thread at Cocoabuilder that seems to relate.
The error something thrown by RegexKitLite when I passed it a problematic string. The error message indicated a system-wide error, which is what confused me for so long.