Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Squirrel Level.edit bug #207

Closed
brmbrmcar opened this issue Oct 27, 2015 · 10 comments
Closed

Squirrel Level.edit bug #207

brmbrmcar opened this issue Oct 27, 2015 · 10 comments
Labels
category:code involves:scripting status:needs-information PR/Issue author needs to provide additional information type:bug
Milestone

Comments

@brmbrmcar
Copy link
Contributor

Running Level.edit(true); then Level.edit(false); closes the game.

@Karkus476
Copy link
Member

The Scripting Reference is here, but it's not clear what this does. What are you trying to do?

@brmbrmcar
Copy link
Contributor Author

Allow the player to look around.

@Hume2 Hume2 added the status:needs-information PR/Issue author needs to provide additional information label Nov 9, 2015
@Hume2
Copy link
Member

Hume2 commented Nov 9, 2015

I can't reproduce it.

@tobbi
Copy link
Member

tobbi commented Nov 15, 2015

Program received signal EXC_BAD_ACCESS, Could not access memory.
Reason: KERN_INVALID_ADDRESS at address: 0x0000000000000004
SQVM::Execute (this=0x10235c660, closure=@0x104082600, nargs=1, stackbase=1, outres=@0x7fff5fbfbb68, raiseerror=1, et=ET_CALL) at supertux/external/squirrel/squirrel/sqvm.cpp:710
710 switch(i.op)
(gdb) bt
0 SQVM::Execute (this=0x10235c660, closure=@0x104082600, nargs=1, stackbase=1, outres=@0x7fff5fbfbb68, raiseerror=1, et=ET_CALL) at supertux/external/squirrel/squirrel/sqvm.cpp:710
1 0x0000000100576f77 in SQVM::Call (this=0x10235c660, closure=@0x104082600, nparams=1, stackbase=1, outres=@0x7fff5fbfbb68, raiseerror=1) at supertux/external/squirrel/squirrel/sqvm.cpp:1545
2 0x0000000100544419 in sq_call (v=0x10235c660, params=1, retval=0, raiseerror=1) at supertux/external/squirrel/squirrel/sqapi.cpp:1155
3 0x000000010022e896 in scripting::compile_and_run (vm=0x10235c660, in=@0x7fff5fbfc910, sourcename=@0x7fff5fbfbdb0) at supertux/src/scripting/squirrel_util.cpp:237
4 0x0000000100451517 in Sector::run_script ()
5 0x00000001004b9c6f in Switch::update (this=0x1020b0538) at supertux/src/trigger/switch.cpp:87
6 0x0000000100454d0d in Sector::update ()
7 0x00000001002c3593 in GameSession::update (this=0x102710d70, elapsed_time=0.015625) at supertux/src/supertux/game_session.cpp:524
8 0x0000000100446a36 in ScreenManager::update_gamelogic (this=0x7fff5fbfd998, elapsed_time=0.015625) at supertux/src/supertux/screen_manager.cpp:219
9 0x00000001004486fe in ScreenManager::run (this=0x7fff5fbfd998, context=@0x7fff5fbfdcb8) at supertux/src/supertux/screen_manager.cpp:416
10 0x00000001002f3047 in Main::launch_game (this=0x7fff5fbffae8) at supertux/src/supertux/main.cpp:448
11 0x00000001002f3b37 in Main::run (this=0x7fff5fbffae8, argc=2, argv=0x7fff5fbffb28) at supertux/src/supertux/main.cpp:504
12 0x0000000100005059 in main (argc=2, argv=0x7fff5fbffb28) at supertux/src/main.cpp:23

@tobbi
Copy link
Member

tobbi commented Nov 15, 2015

bug.stl.txt
(Only press one switch now).

@Hume2 Hume2 changed the title Bug with switches. squirel Level.edit bug Dec 22, 2015
@brmbrmcar brmbrmcar changed the title squirel Level.edit bug Squirrel Level.edit bug Jan 31, 2016
@Karkus476 Karkus476 added this to the 0.5.1 milestone Sep 5, 2016
@christ2go
Copy link
Contributor

christ2go commented Sep 11, 2016

Can reproduce this from the switch, but not when running the same commands through the command line.

@brmbrmcar
Copy link
Contributor Author

No, that doesn't result in anything unusual.

@christ2go
Copy link
Contributor

christ2go commented Sep 11, 2016

My initial assesement was wrong, ... if you seperate the two commands into two switches, the execution of the command Level.edit(false) from the script block causes the game to crash. Level.edit(false) in the standard configuration only causes harm if they level is in editing mode, else nothing is done, nevertheless even if you remove this constraint calling the method anytime causes the same error.

@christ2go
Copy link
Contributor

christ2go commented Sep 15, 2016

I just fixed this bug, the error was, that when edit mode is left, a new level instance is created, and when the squirrel vm calls the closure the level is restarted, and the old level object is destroyed, thus the reference the vm has to the closure function is invalid, possibly when squirrel tries to clean up or something, it tries to access a destroyed object. The easy fix is/would be to have a reference to the level created before the now played level in the GameSession class, then everything works as exspected.
But this does show a fundamental rule about squirrel functions (which mybe should be included in the scripting guide): The closure function which is called must exist until the script is finished / native methods called by squirrel mustn't destroy the object which holds the closure.

Should I open a pr with this fix?

@tobbi
Copy link
Member

tobbi commented Sep 15, 2016

Yes, please do open a PR, and we can take a look at it.

christ2go added a commit to christ2go/supertux that referenced this issue Sep 15, 2016
Using the function Level.edit(false) through a switch when in
edit mode currently causes the game to crash. This is due to
the current Level object being destroyed when the edit mode is
left, but squirrel is still referencing / trying to use it, and
this leads to the seg fault.

The Fix is, that the GameSession object keeps a reference to the
last delteted level, as an extra member variable, thus squirrel
can still access the level object.

Fixes SuperTux#207
christ2go added a commit to christ2go/supertux that referenced this issue Sep 17, 2016
Using the function Level.edit(false) through a switch when in
edit mode currently causes the game to crash. This is due to
the current Level object being destroyed when the edit mode is
left, but squirrel is still referencing / trying to use it, and
this leads to the seg fault.

The Fix is, that the GameSession object keeps a reference to the
last delteted level, as an extra member variable, thus squirrel
can still access the level object.

Fixes SuperTux#207
@tobbi tobbi modified the milestones: 0.5.0, 0.5.1 Sep 17, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
category:code involves:scripting status:needs-information PR/Issue author needs to provide additional information type:bug
Projects
None yet
Development

No branches or pull requests

5 participants