TIC-80 Core Dump On Command Line Launch With Sokol Renderer Troubleshooting
Hey guys! It seems like a user is encountering a pretty interesting issue while trying to run TIC-80 with the Sokol renderer. They've built TIC-80 from the "sokol" branch and are running into a core dump when launching a game from the command line, but only when doing so in this specific way. Let's dive into the details and see if we can figure out what's going on.
The Issue: Core Dumps on Command Line Launch
The main problem, as described by the user, is that when they try to start a game using the command line, TIC-80 crashes with a core dump. This is a rather ungraceful exit and suggests something is going wrong under the hood. The command they are using looks something like this:
./tic80-pro-2025-07-28-sokol data/dungeon23.tic --fs data
Interestingly, the user notes that the build itself seems to be working fine. They can launch TIC-80, load a game from the console within the application, and everything works as expected. Even the CRT shader, which is a nice touch, is functioning correctly. This makes the core dump issue even more peculiar – why only when launching from the command line?
Understanding Core Dumps
For those who aren't familiar, a core dump is essentially a snapshot of the program's memory at the moment it crashed. It's like a forensic report for software, allowing developers to examine the state of the application and potentially pinpoint the cause of the crash. Core dumps can be a goldmine of information, but deciphering them often requires specialized tools and a good understanding of the program's internals.
The Plot Thickens: OpenGL Warnings
The user also mentions seeing some warnings during the build process related to OpenGL:
[sg][warning][id:8] /temp/github2/tic80/2025/TIC-80/vendor/sokol/sokol_gfx.h:9359:0: GL_VERTEX_ATTRIBUTE_NOT_FOUND_IN_SHADER: vertex attribute not found in shader; NOTE: may be caused by GL driver's GLSL compiler removing unused globals
These warnings suggest that there might be some issues with how shaders are being handled, specifically that some vertex attributes expected by the shader are not being found. The warning also hints that the OpenGL driver's GLSL compiler might be optimizing away unused globals, which could be a contributing factor.
Digging Deeper: Potential Causes and Solutions
So, what could be causing this core dump when launching from the command line? Let's explore some potential avenues:
1. Command Line Argument Parsing
Command-line arguments in the TIC-80 when launching with the Sokol renderer may be the first place to investigate when debugging core dumps. One possibility is that there's a bug in how TIC-80 is parsing command-line arguments, especially when using the Sokol renderer. Perhaps a specific combination of arguments, like loading a .tic
file and specifying a file system path (--fs data
), triggers an error. It's crucial to check if the arguments are correctly parsed and passed to the appropriate functions within TIC-80. A debugging session focused on this area may reveal discrepancies in the parsing logic. Using a debugger, one can step through the code that handles command-line input and verify that each argument is interpreted as expected. This meticulous approach can highlight where the process deviates from the norm, potentially exposing the root cause of the core dump.
2. Resource Loading Issues
When launching a game directly from the command line, TIC-80 may encounter issues with resource loading that do not occur when launching the application and then loading a game through the console. The file paths used, especially the --fs data
option, are critical here. It's possible that relative paths are not being resolved correctly in the command-line context, leading to a failure when trying to access game assets. To address this, ensuring that all file paths are correctly formed, whether they are absolute or relative, is essential. One effective debugging technique is to temporarily switch to absolute paths to determine if path resolution is the source of the problem. Additionally, verifying that the necessary files are present in the expected locations can help eliminate common file-not-found errors. These steps will help ensure that resource loading operates smoothly when games are launched via the command line.
3. Sokol Renderer Initialization
The Sokol renderer initialization process could be a source of issues when running TIC-80 from the command line. The way the Sokol renderer is initialized and configured may differ slightly when a game is started directly versus when it's loaded through the console interface. This can result in critical differences in how the rendering context is set up, potentially leading to a crash if certain assumptions are not met. To debug this, it is crucial to inspect the initialization sequence closely, especially the parts that handle OpenGL context creation and shader loading. Comparing the renderer's initialization path between the two launch scenarios can highlight discrepancies. Tools that allow inspecting OpenGL state, such as renderdoc, can be invaluable in pinpointing specific issues with the rendering setup, such as incorrect buffer configurations or shader compilation problems.
4. OpenGL Driver Compatibility
Sometimes, the issue might stem from OpenGL driver compatibility, particularly with the Sokol renderer which directly interfaces with OpenGL. The warnings about vertex attributes not found in the shader may suggest underlying problems with how the graphics drivers handle shader compilation and execution. Differences in driver behavior across different environments or command-line execution contexts could exacerbate these issues. To mitigate this, updating graphics drivers to the latest stable version is a crucial first step, ensuring that the most recent fixes and optimizations are in place. Additionally, testing TIC-80 on different systems with varying hardware and driver configurations can help determine if the issue is specific to a particular setup or more widespread. If problems persist, consulting the driver documentation or forums may provide insights into known issues or specific settings that can improve compatibility.
5. Memory Corruption
Memory corruption is a sinister issue that can be difficult to diagnose, and it's a possible culprit behind the crashes seen in TIC-80 when launched from the command line. This happens when the application writes to a memory location it shouldn't, potentially overwriting crucial data structures or code. Such errors might only manifest under specific conditions, such as the command-line launch scenario, where the memory layout or the timing of operations can differ slightly from running within the console. Tools designed for memory debugging, like Valgrind, are invaluable in these situations. These tools monitor memory accesses and can detect common errors like buffer overflows, use-after-free, and other memory-related issues. Running TIC-80 under Valgrind or similar tools can provide a detailed report of memory operations, helping to pinpoint exactly where and why memory corruption occurs. Addressing these issues often requires careful code review and modification to ensure memory safety.
Reproducing the Issue and Gathering More Information
To effectively diagnose the problem, it's essential to try and reproduce the issue in a controlled environment. This might involve:
- Building TIC-80 from the same commit hash as the user (7effb96).
- Using the same build configuration (cmake flags).
- Running the same command line command.
- Examining the core dump file using a debugger like
gdb
.
Gathering more information from the user is also crucial. We might want to know:
- The operating system they are using.
- The graphics card and driver version.
- The exact steps they took to build TIC-80.
- If they have tried running other games from the command line.
Next Steps: A Collaborative Debugging Effort
This is an interesting problem that highlights the complexities of software development, especially when dealing with rendering and platform-specific issues. By systematically investigating the potential causes and gathering more information, we can hopefully help the user resolve this core dump issue and get back to making awesome games with TIC-80. Let's work together to figure this out!