scp-fs2open / fs2open.github.com

Origin Repository for SCP FreeSpace 2 Open
https://www.hard-light.net/
Other
401 stars 161 forks source link

Lua does not complain when attempting to index a nil value #1241

Closed X3N0-Life-Form closed 7 years ago

X3N0-Life-Form commented 7 years ago

While doing some scripting, I noticed some functions would just stop way before hitting "return".

After a bit of digging, it turns out that the lua interpreter does not always throw a warning when attempting to index a nil value, but seemingly crashes nonetheless.

For instance, the sample code below throws out warning steps 1 through 3, but not the final warning, and the debug log shows nothing out of the ordinary (see below).

Tested on master pulled & compiled 24 hours ago.

Note : I tried attaching a sample mod, but the upload kept failing for some reason.

#Conditional Hooks
$Application: FS2_Open

;; Test
$On Game Init: [

    local testTable = {}
    testTable['exist'] = {}
    testTable['exist']['value'] = "test"

    ba.warning("step 1")
    local a = testTable['exist']['value']
    ba.print(a)

    ba.warning("step 2")
    local b = testTable['exist']
    ba.print(b)

    ba.warning("step 3")
    local c = testTable['does not exist']['value']
    ba.print(c)

    ba.warning("done")
]

#End

Debug log when trying to run the script above

==========================================================================
DEBUG SPEW: No debug_filter.cfg found, so only general, error, and warning
categories can be shown and no debug_filter.cfg info will be saved.
==========================================================================
  Initializing SDL...
FreeSpace 2 Open version: 3.7.5
Passed cmdline options:
  -spec_exp 11
  -spec_static 0.8
  -spec_point 0.6
  -ambient_factor 25
  -3dshockwave
  -soft_particles
  -post_process
  -fxaa
  -fb_explosions
  -fb_thrusters
  -enable_shadows
  -rearm_timer
  -targetinfo
  -3dwarp
  -ship_choice_3d
  -weapon_choice_3d
  -warp_flash
  -mod nil index test
  -res 1920x1080
  -output_scripting
Building file index...
Found root pack 'C:\FreeSpace 2\multi-mission-pack.vp' with a checksum of 0x377695e0
Found root pack 'C:\FreeSpace 2\multi-voice-pack.vp' with a checksum of 0xd50e7442
Found root pack 'C:\FreeSpace 2\Root_fs2.vp' with a checksum of 0xce10d76c
Found root pack 'C:\FreeSpace 2\smarty_fs2.vp' with a checksum of 0xddeb3b1e
Found root pack 'C:\FreeSpace 2\sparky_fs2.vp' with a checksum of 0x164fe65a
Found root pack 'C:\FreeSpace 2\sparky_hi_fs2.vp' with a checksum of 0xa11d56f1
Found root pack 'C:\FreeSpace 2\stu_fs2.vp' with a checksum of 0xd77da83a
Found root pack 'C:\FreeSpace 2\tango1_fs2.vp' with a checksum of 0x4c25221e
Found root pack 'C:\FreeSpace 2\tango2_fs2.vp' with a checksum of 0x86920b82
Found root pack 'C:\FreeSpace 2\tango3_fs2.vp' with a checksum of 0x705e8d71
Found root pack 'C:\FreeSpace 2\warble_fs2.vp' with a checksum of 0xd85c305d
Searching root 'C:\Users\Tol Hrorim\AppData\Roaming\HardLightProductions\FreeSpaceOpen\nil index test\' ... 0 files
Searching root 'C:\Users\Tol Hrorim\AppData\Roaming\HardLightProductions\FreeSpaceOpen\' ... 4 files
Searching root 'C:\FreeSpace 2\nil index test\' ... 1 files
Searching root 'C:\FreeSpace 2\' ... 25 files
Searching root pack 'C:\FreeSpace 2\multi-mission-pack.vp' ... 110 files
Searching root pack 'C:\FreeSpace 2\multi-voice-pack.vp' ... 307 files
Searching root pack 'C:\FreeSpace 2\Root_fs2.vp' ... 157 files
Searching root pack 'C:\FreeSpace 2\smarty_fs2.vp' ... 10 files
Searching root pack 'C:\FreeSpace 2\sparky_fs2.vp' ... 3027 files
Searching root pack 'C:\FreeSpace 2\sparky_hi_fs2.vp' ... 1337 files
Searching root pack 'C:\FreeSpace 2\stu_fs2.vp' ... 2355 files
Searching root pack 'C:\FreeSpace 2\tango1_fs2.vp' ... 32 files
Searching root pack 'C:\FreeSpace 2\tango2_fs2.vp' ... 15 files
Searching root pack 'C:\FreeSpace 2\tango3_fs2.vp' ... 10 files
Searching root pack 'C:\FreeSpace 2\warble_fs2.vp' ... 52 files
Found 15 roots and 7442 files.
AutoLang: Language auto-detection successful...
Setting language to English
Game Settings Table: Using Standard Loops For SEXP Arguments
Game Settings Table: Using standard event chaining behavior
Game Settings Table: External shaders are DISABLED
Initializing OpenAL...
  OpenAL Vendor     : Creative Labs Inc.
  OpenAL Renderer   : Software
  OpenAL Version    : 1.1

  Found extension "ALC_EXT_EFX".
You are not using OpenAL Soft. Disabling enhanced sound.

  Sample rate: 44100 (44100)
  EFX enabled: NO
  Playback device: Generic Software on Speakers (Realtek High Definition Audio)
  Capture device: Microphone (Realtek High Defini
... OpenAL successfully initialized!
  Initializing SDL video...
Initializing OpenGL graphics device at 1920x1080 with 32-bit color...
  Requested SDL Pixel values = R: 8, G: 8, B: 8, depth: 24, stencil: 8, double-buffer: 1, FSAA: 0
SDL: Creating window at 0,0 because window has same size as desktop.
  Requested SDL Pixel values = R: 8, G: 8, B: 8, depth: 24, stencil: 8, double-buffer: 1, FSAA: 0
  Actual SDL Video values    = R: 8, G: 8, B: 8, depth: 24, stencil: 8, double-buffer: 1, FSAA: 0
  OpenGL Vendor    : NVIDIA Corporation
  OpenGL Renderer  : GeForce 940M/PCIe/SSE2
  OpenGL Version   : 4.1.0 NVIDIA 369.09

Compiling new shader:
    Particle Effects
   Loading built-in default shader for: effect-v.sdr
   Loading built-in default shader for: effect-particle-f.sdr
Shader Variant Features:
Compiling new shader:
    Particle Effects
   Loading built-in default shader for: effect-v.sdr
   Loading built-in default shader for: effect-particle-f.sdr
   Loading built-in default shader for: effect-screen-g.sdr
Shader Variant Features:
    Geometry shader point-based particles
Compiling new shader:
    Distortion Effects
   Loading built-in default shader for: effect-distort-v.sdr
   Loading built-in default shader for: effect-distort-f.sdr
Shader Variant Features:
Compiling new shader:
    Shield Decals
   Loading built-in default shader for: shield-impact-v.sdr
   Loading built-in default shader for: shield-impact-f.sdr
Shader Variant Features:
Compiling new shader:
    Deferred Lighting
   Loading built-in default shader for: deferred-v.sdr
   Loading built-in default shader for: deferred-f.sdr
WARNING: Failed to find uniform 'specFactor'.
Shader Variant Features:
Compiling new shader:
    Clear Deferred Lighting Buffer
   Loading built-in default shader for: deferred-clear-v.sdr
   Loading built-in default shader for: deferred-clear-f.sdr
Shader Variant Features:
Compiling passthrough shader...
Compiling new shader:
    Passthrough
   Loading built-in default shader for: passthrough-v.sdr
   Loading built-in default shader for: passthrough-f.sdr
Shader Variant Features:

Compiling passthrough shader...
Compiling new shader:
    Post Processing
   Loading built-in default shader for: post-v.sdr
   Loading built-in default shader for: post-f.sdr
WARNING: Failed to find uniform 'depth_tex'.
WARNING: Failed to find uniform 'timer'.
Shader Variant Features:
Compiling new shader:
    Bloom Brightpass
   Loading built-in default shader for: post-v.sdr
   Loading built-in default shader for: brightpass-f.sdr
Shader Variant Features:
Compiling new shader:
    Gaussian Blur
   Loading built-in default shader for: post-v.sdr
   Loading built-in default shader for: blur-f.sdr
WARNING: Failed to find uniform 'debug'.
Shader Variant Features:
    Horizontal blur pass
Compiling new shader:
    Gaussian Blur
   Loading built-in default shader for: post-v.sdr
   Loading built-in default shader for: blur-f.sdr
WARNING: Failed to find uniform 'debug'.
Shader Variant Features:
    Vertical blur pass
Compiling new shader:
    Bloom Compositing
   Loading built-in default shader for: post-v.sdr
   Loading built-in default shader for: bloom-comp-f.sdr
Shader Variant Features:
Compiling new shader:
    FXAA
   Loading built-in default shader for: fxaa-v.sdr
   Loading built-in default shader for: fxaa-f.sdr
Shader Variant Features:
Compiling new shader:
    FXAA Prepass
   Loading built-in default shader for: post-v.sdr
   Loading built-in default shader for: fxaapre-f.sdr
Shader Variant Features:
  Max texture units: 2 (32)
  Max client texture states: 2 (1)
  Max elements vertices: 1048576
  Max elements indices: 1048576
  Max texture size: 16384x16384
  Max render buffer size: 16384x16384
  Can use compressed textures: YES
  Texture compression available: YES
  Post-processing enabled: YES
  Using trilinear texture filter.
  OpenGL Shader Version: 4.10 NVIDIA via Cg compiler
... OpenGL init is complete!
Initializing path renderer...
Size of bitmap info = 1039 KB
Size of bitmap extra info = 64 bytes
ANI cursorweb with size 24x24 (25.0% wasted)
ANI cursorweb.ani with size 24x24 (25.0% wasted)
GRAPHICS: Initializing default colors...
SCRIPTING: Beginning initialization sequence...
SCRIPTING: Beginning Lua initialization...
LUA: Opening LUA state...
LUA: Initializing base Lua libraries...
LUA: Beginning ADE initialization
ADE: Initializing enumeration constants...
ADE: Assigning Lua session...
SCRIPTING: Outputting scripting metadata...
SCRIPTING: Beginning main hook parse sequence....
Wokka!  Error opening file (scripting.tbl)!
TABLES: Unable to parse 'scripting.tbl'!  Error message = Failed to open file.
TBM  =>  Starting parse of 'test-sct.tbm' ...
SCRIPTING: Inititialization complete.
SCRIPTING: Splash screen overrides checked
SCRIPTING: Splash screen conditional hook has been run
Using high memory settings...
Wokka!  Error opening file (interface.tbl)!
WMCGUI: Unable to parse 'interface.tbl'!  Error message = Failed to open file.
Dutifully converting retail sound 36, 'l_hit.wav' to a 3D sound...
Dutifully converting retail sound 37, 'm_hit.wav' to a 3D sound...
Initializing Joystick...
  No joysticks found
Printing joystick info:
  No joystick is being used.
Current soundtrack set to -1 in event_music_reset_choices
Wokka!  Error opening file (armor.tbl)!
TABLES: Unable to parse 'armor.tbl'!  Error message = Failed to open file.
ANI support1 with size 108x24 (25.0% wasted)
ANI damage1 with size 148x25 (21.9% wasted)
ANI wingman1 with size 71x53 (17.2% wasted)
ANI wingman2 with size 35x53 (17.2% wasted)
ANI wingman3 with size 14x53 (17.2% wasted)
ANI toggle1 with size 57x20 (37.5% wasted)
ANI head1 with size 164x132 (48.4% wasted)
ANI weapons1 with size 126x20 (37.5% wasted)
ANI objective1 with size 149x21 (34.4% wasted)
ANI netlag1 with size 29x30 (6.3% wasted)
ANI targhit1 with size 31x21 (34.4% wasted)
ANI time1 with size 47x23 (28.1% wasted)
ANI targetview1 with size 137x156 (39.1% wasted)
ANI targetview2 with size 4x96 (25.0% wasted)
ANI targetview3 with size 7x20 (37.5% wasted)
ANI 2_energy2 with size 86x96 (25.0% wasted)
ANI 2_reticle1 with size 40x24 (25.0% wasted)
ANI 2_leftarc with size 103x252 (1.6% wasted)
ANI 2_rightarc1 with size 103x252 (1.6% wasted)
ANI 2_toparc2 with size 35x24 (25.0% wasted)
ANI 2_toparc3 with size 41x29 (9.4% wasted)
ANI 2_lead1 with size 26x26 (18.8% wasted)
ANI 2_lock1 with size 56x53 (17.2% wasted)
ANI 2_lockspin with size 100x100 (21.9% wasted)
ANI energy1 with size 12x41 (35.9% wasted)
ANI 2_radar1 with size 209x170 (33.6% wasted)
TABLES => Starting parse of 'ssm.tbl'...
ANI cursor with size 24x24 (25.0% wasted)
ANI cursor.ani with size 24x24 (25.0% wasted)
WARNING: "step 1" at base.cpp:34
testWARNING: "step 2" at base.cpp:34
(null)WARNING: "step 3" at base.cpp:34
FFmpeg library initialized!
FFmpeg: License: LGPL version 2.1 or later
Ships.tbl is : VALID
Weapons.tbl is : VALID
cfile_init() took 118
Initializing head tracking...
Failed to load library 'scptrackir.dll': 'Failed loading scptrackir.dll: @'
TrackIR Init Failed - -1
    Failed to initialize 'TrackIR': Failed to initialize TrackIR.
Failed to load library '': 'Failed loading : Paramètre incorrect.
'
    Failed to initialize 'FreeTrack': Library could not be loaded!.
  No supported provider found, headtracking will be disabled...
Headtracking is not enabled...
Creating player for movie 'intro.mve'.
FFMPEG Log: [theora @ 00000000021dbe00] 7 bits left in packet 82
FFMPEG Log: [ogg @ 00000000021dae20] Broken file, keyframe not correctly marked.
FFMPEG Log: [theora @ 00000000021e21e0] 7 bits left in packet 82
FFmpeg: Using video codec Theora (theora).
FFmpeg: Using audio codec Vorbis (vorbis).
Compiling new shader:
    Video Playback
   Loading built-in default shader for: video-v.sdr
   Loading built-in default shader for: video-f.sdr
Shader Variant Features:
FFMPEG Log: [ogg @ 00000000021dae20] Broken file, keyframe not correctly marked.
FFMPEG Log: [ogg @ 00000000021dae20] Broken file, keyframe not correctly marked.
FFMPEG Log: [ogg @ 00000000021dae20] Broken file, keyframe not correctly marked.
FFMPEG Log: [ogg @ 00000000021dae20] Broken file, keyframe not correctly marked.
X3N0-Life-Form commented 7 years ago

Additionnal info, the jan 2nd nightly complains, but the feb 2nd does not.

WARNING: "step 1" at base.cpp:34
testWARNING: "step 2" at base.cpp:34
(null)WARNING: "step 3" at base.cpp:34
Lua Error: LUA ERROR: [string "test-sct.tbm - On Game Init"]:14: attempt to index field 'does not exist' (a nil value)

------------------------------------------------------------------
ADE Debug:
------------------------------------------------------------------
------------------------------------------------------------------

------------------------------------------------------------------

stack traceback:
    [C]: ?
    [string "test-sct.tbm - On Game Init"]:14: in main chunk
------------------------------------------------------------------

------------------------------------------------------------------
asarium commented 7 years ago

Can you narrow down which nightly build works and which doesn't?

X3N0-Life-Form commented 7 years ago

Did some further testing, something broke between the january 2nd & 3rd builds.

asarium commented 7 years ago

There was a change to how the lua functions were handled in that nightly so that is likely the cause.

asarium commented 7 years ago

Found the issue, I'm an idiot.