[Resolved] What's Happening?

I’ve got a moderately well-working game that has a level select screen with buttons to go to each level. It works fine, goes to the level, you play the level… When it goes back to the level select screen, it looks fine. However, click a button to go to another level and - poof! - the Spinning Beach Ball of Doom appears and Corona Simulator quits and I’m left with a crashed Corona Simulator. In the terminal, it’s got this message:

[text]
/Applications/CoronaSDK/Corona Terminal: line 9: 8008 Segmentation fault: 11 “$path/Corona Simulator.app/Contents/MacOS/Corona Simulator” $*
logout

[Process Completed]
[/text]

I also get a large “Corona Simulator Quit Unexpectedly” screen.

The odd thing is that it only does that at the second or third starting of a level. It has no discrimination of which level - if you play the first level through and try to start the first level again, it crashes. Or if you play the third level through and try to start the fourth level, it crashes. And, I checked the memory usage: I’m destroying all objects and when it leaves the level no memory is staying except for that which is used for the level select scene. But when I click the button, the memory checker stops and it crashes.

Any help would be greatly appreciated. [import]uid: 147322 topic_id: 32988 reply_id: 332988[/import]

Often when this happens you either have a physics issue or, less commonly, an audio issue. It can happen with any serious issue in your code, mind you - have also seen it with sprites - but most commonly it seems to be associated with physics.

When it quits, it’s at the start of loading a new level, just seemingly random when it occurs? If so I’d look at what you do during initial setup of each level and try commenting some things out, testing, etc. as that’s likely where the issue is. [import]uid: 52491 topic_id: 32988 reply_id: 130980[/import]

When in doubt, carpet bombing the area with print statements can help isolate the area… (Remove all the prints after you’ve fixed the issue of course).

5 minutes of pasting print statements in (even if they are print(" --a"), print(" --b"), and a couple runs of the app, and you might turn something up that leads to something, that leads to something else, that points at the problem! Let the hunt begin, let loose the prints of war!

Well, it’s either that, or shell out a few bucks for one of them there fancy debuggers I keep hearing about. [import]uid: 79933 topic_id: 32988 reply_id: 130981[/import]

A Single 11 SIGSEGV Segment Violation according to Wikipedia:

A segmentation fault (often shortened to segfault), bus error or access violation is generally an attempt to access memory that the CPU cannot physically address. It occurs when the hardware notifies an operating system about a memory access violation. The OS kernel then sends a signal to the process which caused the exception. By default, the process receiving the signal dumps core and terminates. The default signal handler can also be overridden to customize how the signal is handled.[1]

Of course iOS and OS-X has core dumps turned off. But what all that means is that if you have something that is a pointer, like a display object or a table that has an address that is some big hex number like: 0x82A8949339. If that variable gets overwritten with a number that isn’t a valid memory address, you will crash with a segment violation.

  
local button = display.newImageRect("someimage.png",somewidth,someheight)  
  
button = 10  
  
group:insert(button)  
  

The insert method will go try and read a display object from memory location 10, which your app doesn’t have access to and BOOM… Segment Violation.

You are likely calling a function that’s been removed, or you’ve overwritten something with a simple variable.
[import]uid: 19626 topic_id: 32988 reply_id: 130997[/import]

Often when this happens you either have a physics issue or, less commonly, an audio issue. It can happen with any serious issue in your code, mind you - have also seen it with sprites - but most commonly it seems to be associated with physics.

When it quits, it’s at the start of loading a new level, just seemingly random when it occurs? If so I’d look at what you do during initial setup of each level and try commenting some things out, testing, etc. as that’s likely where the issue is. [import]uid: 52491 topic_id: 32988 reply_id: 130980[/import]

When in doubt, carpet bombing the area with print statements can help isolate the area… (Remove all the prints after you’ve fixed the issue of course).

5 minutes of pasting print statements in (even if they are print(" --a"), print(" --b"), and a couple runs of the app, and you might turn something up that leads to something, that leads to something else, that points at the problem! Let the hunt begin, let loose the prints of war!

Well, it’s either that, or shell out a few bucks for one of them there fancy debuggers I keep hearing about. [import]uid: 79933 topic_id: 32988 reply_id: 130981[/import]

A Single 11 SIGSEGV Segment Violation according to Wikipedia:

A segmentation fault (often shortened to segfault), bus error or access violation is generally an attempt to access memory that the CPU cannot physically address. It occurs when the hardware notifies an operating system about a memory access violation. The OS kernel then sends a signal to the process which caused the exception. By default, the process receiving the signal dumps core and terminates. The default signal handler can also be overridden to customize how the signal is handled.[1]

Of course iOS and OS-X has core dumps turned off. But what all that means is that if you have something that is a pointer, like a display object or a table that has an address that is some big hex number like: 0x82A8949339. If that variable gets overwritten with a number that isn’t a valid memory address, you will crash with a segment violation.

  
local button = display.newImageRect("someimage.png",somewidth,someheight)  
  
button = 10  
  
group:insert(button)  
  

The insert method will go try and read a display object from memory location 10, which your app doesn’t have access to and BOOM… Segment Violation.

You are likely calling a function that’s been removed, or you’ve overwritten something with a simple variable.
[import]uid: 19626 topic_id: 32988 reply_id: 130997[/import]

Overwritten objects/functions are a leading cause.
Having a timer or runtime event handler in a module that gets swapped out of memory with Director or Storyboard can cause this.
Peach listed some prime examples that cause it as well.

Make sure if your using a scene manager like Director or Storyboard that you are stopping everything that runs in the background (Physics, timers, transitions that have onCompelete call backs, audio.play() that has onComplete call backs) [import]uid: 19626 topic_id: 32988 reply_id: 131080[/import]

Overwritten objects/functions are a leading cause.
Having a timer or runtime event handler in a module that gets swapped out of memory with Director or Storyboard can cause this.
Peach listed some prime examples that cause it as well.

Make sure if your using a scene manager like Director or Storyboard that you are stopping everything that runs in the background (Physics, timers, transitions that have onCompelete call backs, audio.play() that has onComplete call backs) [import]uid: 19626 topic_id: 32988 reply_id: 131080[/import]

Thanks, everyone!

@Peach Pellen:
Well, in the level select screen, as I said before, I have the buttons to the level. You click the button, and if it’s the time that it decides to crash, the button’s “over” image doesn’t even display. And it crashes… Again. But… Physics? (I don’t have any audio - yet) That seems interesting…

@mpappas:
Thanks for the input. I’ll be sure to use the “Prints of War” :slight_smile:

@robmiracle:
I see… So to sum it up, what I’m getting is a problem with identifying an object? As in I might be overwriting something and then trying to get it as something it’s not?

@All:
Thanks for everyone’s help again! I think I might be making some headway. With the Prints of War, I’ve found out that the problem does not occur if you leave the level through the pause screen. So it’s something I’m doing (or not doing) when you complete the level.

Caleb [import]uid: 147322 topic_id: 32988 reply_id: 131058[/import]

Update:
The problem is for some reason with the level selection buttons for sure. I created a blank button that goes nowhere to test it with and the simulator doesn’t crash until you try to press a button. I’ll look further into that. [import]uid: 147322 topic_id: 32988 reply_id: 131131[/import]

Thanks, everyone!

@Peach Pellen:
Well, in the level select screen, as I said before, I have the buttons to the level. You click the button, and if it’s the time that it decides to crash, the button’s “over” image doesn’t even display. And it crashes… Again. But… Physics? (I don’t have any audio - yet) That seems interesting…

@mpappas:
Thanks for the input. I’ll be sure to use the “Prints of War” :slight_smile:

@robmiracle:
I see… So to sum it up, what I’m getting is a problem with identifying an object? As in I might be overwriting something and then trying to get it as something it’s not?

@All:
Thanks for everyone’s help again! I think I might be making some headway. With the Prints of War, I’ve found out that the problem does not occur if you leave the level through the pause screen. So it’s something I’m doing (or not doing) when you complete the level.

Caleb [import]uid: 147322 topic_id: 32988 reply_id: 131058[/import]

Update:
The problem is for some reason with the level selection buttons for sure. I created a blank button that goes nowhere to test it with and the simulator doesn’t crash until you try to press a button. I’ll look further into that. [import]uid: 147322 topic_id: 32988 reply_id: 131131[/import]

Great, great, great! Solved the problem. It was not with the level selection buttons. It turned out I wasn’t removing a touch listener, so when I touched the screen, it was APPLYING FORCE to an object that was not there. (note the physics applyForce problem!)

Thanks so much for everyone’s help! [import]uid: 147322 topic_id: 32988 reply_id: 131566[/import]

Congrats Caleb! Sounds like you turned something up that led to something, that led to something else, that pointed at the problem!

Ya know what they say, if it was easy, it wouldn’t feel as good :slight_smile: [import]uid: 79933 topic_id: 32988 reply_id: 131569[/import]

Great, great, great! Solved the problem. It was not with the level selection buttons. It turned out I wasn’t removing a touch listener, so when I touched the screen, it was APPLYING FORCE to an object that was not there. (note the physics applyForce problem!)

Thanks so much for everyone’s help! [import]uid: 147322 topic_id: 32988 reply_id: 131566[/import]

Congrats Caleb! Sounds like you turned something up that led to something, that led to something else, that pointed at the problem!

Ya know what they say, if it was easy, it wouldn’t feel as good :slight_smile: [import]uid: 79933 topic_id: 32988 reply_id: 131569[/import]