MonoDevelop Debugger Crashing with no error message, using Dijkstra's algorithm and 2D array-Collection of common programming errors
I’m making an iOS game in Monotouch with C# and MonoDevelop. I’m having a very strange crash.
Background Information: Making a 2D war game. I’ve implemented Dijkstra’s algorithm to calculate the shortest path from source to destination with objects in-between (example: go from here to there but go around the cars/trees/buildings/or anything in the way automatically). My crash seems to be related to the 2D array of bytes that I created for this implementation of Dijkstra’s algorithm. See this image if you’ve never heard of Dijkstra’s algorithm http://en.wikipedia.org/wiki/File:Dijkstras_progress_animation.gif
Basically, the more nodes I have in my 2D array, the more detail in the soldier’s movement on the battlefield. If I use 2,400 nodes in my 2D array, everything works/loads fine. However, if I increase the number of nodes to 4,266 for more detailed coordinates, the program crashes when it’s calculating the node’s distances. It get’s approximately 30% finished before it crashes.
More Details on the crash: it only crashes when I use Debug/iPhone mode or Release/iPhone mode. When I use the Debug/iPhone Simulator it works fine. And another note, when I build the app and transfer it to my phone using Debug/iPhone mode, then stop the debugger, open XCode Instruments, it works fine! I can’t figure out why it would work in the simulator and with XCode Instruments but NOT with the Monodevelop Debug/iPhone mode. Is XCode Instruments doing something that “patches” up the problem? Or is MonoDevelop’s debugger doing something to “break” the program?

Let me explain what you’re looking at in the screenshot. My app is called “WarGame”. Looking at the timeline, the CPU usage was ~100% from around 2 seconds to about 35 seconds. When the CPU usage drops down to zero, it’s finished loading. So it literally took about 33 seconds to load the 2D Array of Nodes and populate them with Distances.
Keep in mind in this instance that crashes there are 4,266 nodes which means that the 2D array is a byte [4266, 4266] array. So that’s 18,198,756 bytes in a 2D array. And it loads successfully when being run by XCode Instruments and it loads successfully when run in MonoDevelop’s Debug/iPhone Simulator. But it crashes with no error message when run in the Debug/iPhone mode on my iPhone 4s. The memory usage of this app is approximately 60.73MB seen in the screenshots.
In the instance that does NOT crash, there were 2,400 nodes which means that the 2D array is a byte [2400, 2400] array. So that’s 5,760,000 bytes in a 2D array. And that one worked fine everywhere.
The problem clearly seems to be, when I increase the number of nodes to around 4,266 or more the program crashes. But I don’t get an error message, it just stops suddenly when it’s loading… Could this be a garbage collection issue? You’d think I’d get an error message for that right? Could this be an “out of memory” issue? But when it loads using XCode’s Instruments it says I’m only using 60MB, and I’ve used up to 150MB in this app as a test before, so I know I can atleast go up to 150MB of memory usage before it crashes with an “out of memory error”.
Here’s a shot of the memory allocations from XCode Instruments
Here’s a shot of the memory leak’s page from XCode Instruments