Skip to content

🐛 Bug: Global mutable state with no thread safety + unbounded control input accumulation #1

@vietanhrs

Description

@vietanhrs

Issues Found

1. 🐛 Global mutable state with no thread safety (main424.py:15-19)

roll_ctrl = 0
pitch_ctrl = 0
throttle_ctrl = 0
yaw_ctrl = 0

These globals are written by key_on_press (in keyboard listener thread) and read by the drone controller (main thread). No lock/mutex protection — classic data race. For a drone control system, corrupted control values could cause dangerous flight behavior.

Fix: Use threading.Lock() or queue.Queue for thread-safe communication.

2. 🐛 Control inputs accumulate without bounds (main424.py:50-62)

pitch_ctrl += key_press_delta  # Just keeps adding
roll_ctrl += key_press_delta   # No max limit

Holding a key continuously adds to the control value with no upper bound. This could result in extremely large velocity commands sent to the drone.

Fix: Clamp values: pitch_ctrl = min(max_val, pitch_ctrl + delta)

3. 🏗️ Typo in comment (main424.py:15)

# A global variale  # should be 'variable'

4. 🧹 Hardcoded file path (main424.py:32)

config.json path is relative — will break if script is run from a different directory.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions