Project

Profile

Help

HostedRedmine.com has moved to the Planio platform. All logins and passwords remained the same. All users will be able to login and use Redmine just as before. Read more...

Bug #880869

Some bug with tolua-5.2 garbage collecting Direction objects

Added by Alexandro Ignatiev about 1 year ago. Updated 9 months ago.

Status:
Closed
Priority:
Normal
Category:
Scripting API
Sprint/Milestone:
Start date:
Due date:
% Done:

0%

Estimated time:

Description

To reproduce, just type consequently in client Lua console, replace 154 on any visible unit id:

c = find.unit(nil,154)
d= c:facing()
c=nil
d=nil
collectgarbage()

If you collect only the unit, there is no failure, but the queer Direction object fails the client.
Backtrace shows calling NULL in such a stack:
(gdb) backtrace
#0  0x0000000000000000 in  ()
#1  0x0000555555696f57 in luaD_precall
    (L=L@entry=0x555555b310a8, func=0x555556d0c1b0, nresults=0) at ldo.c:434
...
#5  0x00005555556aa401 in class_gc_event (L=0x555555b310a8) at tolua_event.c:392
...
(gdb) print func
$1 = (StkId) 0x555556d0c1b0
(gdb) print *func
$2 = {value_ = {gc = 0x0, p = 0x0, b = 0, f = 0x0, i = 0, n = 0}, tt_ = 22}

no-segfault-Direction-gc.patch (10.1 KB) no-segfault-Direction-gc.patch Alexandro Ignatiev, 2020-07-12 08:22 PM
no-segfault-Direction-gc2.patch (9.87 KB) no-segfault-Direction-gc2.patch Alexandro Ignatiev, 2020-07-13 08:46 PM
no-segfault-Direction-gc3.patch (9.84 KB) no-segfault-Direction-gc3.patch Alexandro Ignatiev, 2020-07-14 06:08 PM
no-segfault-Direction-gc4.patch (9.6 KB) no-segfault-Direction-gc4.patch the working patch preventing segfaults from tolua gc Alexandro Ignatiev, 2020-07-14 09:16 PM
0016-Scripting-Fix-segfaults-with-Direction-objects.patch (9.7 KB) 0016-Scripting-Fix-segfaults-with-Direction-objects.patch master Marko Lindqvist, 2020-08-02 02:09 PM

Related issues

Has duplicate Freeciv - Bug #688119: Intermittent segfault invoking Lua direction functionsClosed

<a title="Actions" class="icon-only icon-actions js-contextmenu" href="#">Actions</a>
Blocks Freeciv - Bug #880895: Global variables with directions result in broken savegamesIn Progress

<a title="Actions" class="icon-only icon-actions js-contextmenu" href="#">Actions</a>

History

#1 Updated by Marko Lindqvist about 1 year ago

  • Related to Bug #688119: Intermittent segfault invoking Lua direction functions added

#2 Updated by Alexandro Ignatiev about 1 year ago

It's a tolua problem with returning user types in C projects: it does not supply any garbagecollector but tries to call it. I've made a patch that uses my own collector. It's still a question if we really need to put 4-bit enum into a dynamically allocated object but this patch keeps current behaviour produces objects as it's done now for valid directions and returns nil for invalid ones, but currently direction.next_ccw(direction.str2dir("somewhere")) just hangs the application and it's a bad idea to turn units into invalid directions, so I think nothing meaningful is harmed.

#3 Updated by Alexandro Ignatiev about 1 year ago

Well, this is shooting a cannon at sparrows, also, still eats up memory. Let's remember this way for some better task like creating virtual units (or just fix a couple of lines in tolua code) and now put a more adequate solution with returning all directions from a static array.
EDIT: testing found abnormal jumping between "const Direction" and "Direction" classes, something wrong...

#4 Updated by Alexandro Ignatiev about 1 year ago

All what was needed is just removing const's from tolua functions. This tolua version does not interest const function modifiers except giving different methods (needs clarification but you understand how const objects can be violated...) Now it does not segfault on gc.

#5 Updated by Alexandro Ignatiev about 1 year ago

  • Blocks Bug #880895: Global variables with directions result in broken savegames added

#6 Updated by Alexandro Ignatiev about 1 year ago

Finally, I made the patch working with mainstream S2_6 branch and put it on the right ticket %\

#7 Updated by Marko Lindqvist 12 months ago

  • Related to deleted (Bug #688119: Intermittent segfault invoking Lua direction functions)

#8 Updated by Marko Lindqvist 12 months ago

  • Has duplicate Bug #688119: Intermittent segfault invoking Lua direction functions added

#9 Updated by Marko Lindqvist 12 months ago

Ported to master.

#10 Updated by Marko Lindqvist 12 months ago

  • Status changed from Resolved to Closed

#11 Updated by Marko Lindqvist 9 months ago

  • Sprint/Milestone changed from 2.6.3 to 2.6.2.1

Also available in: Atom PDF