Code Monkey home page Code Monkey logo

nes-emulator's People

Contributors

donbright avatar michaelburge avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

nes-emulator's Issues

Getting things working on Windows

Hey there,

So, I can't 100% get this running (Rust-SDL2/rust-sdl2#865), but I wanted to show you a diff that I think will get things working:

diff --git a/src/headless.rs b/src/headless.rs
index dbe25e0..73f831a 100644
--- a/src/headless.rs
+++ b/src/headless.rs
@@ -14,7 +14,6 @@ use std::io::Read;
 use std::io::Write;
 use std::fs::File;
 use std::fmt::Debug;
-use std::os::unix::io::FromRawFd;

 use crate::joystick::Joystick;
 use crate::mapper::AddressSpace;
@@ -27,8 +26,8 @@ use crate::common::Clocked;

 fn main() {
     // Standard stdout() object is line-buffered
-    let stdin = unsafe { File::from_raw_fd(0) };
-    let stdout = unsafe { File::from_raw_fd(1) };
+    let stdin = std::io::stdin();
+    let stdout = std::io::stdout();
     let mut headless = Headless::new(
         Box::new(stdin),
         Box::new(stdout),

In general, using the standard library here helps with portability. Of course, it's your project, and so feel free to ignore/close this issue!

Dereferencing Headless::joystick1 is UB

unsafe { (*self.joystick1).set_buttons(button_mask) };

https://doc.rust-lang.org/reference/behavior-considered-undefined.html : Dereferencing a null or dangling raw pointer.

Headless::joystick1/2 are initialized with:

impl Headless {
    fn command_load_rom(&mut self) {
        let mut record_tas = self.read_byte();
        let filename = self.read_length_string();
        let mut joystick1 = Box::new(Joystick::new());
        let mut joystick2 = Box::new(Joystick::new());
        self.joystick1 = &mut *joystick1;
        self.joystick2 = &mut *joystick2;
        ...
        // drop joystick1 joystick2
        // Headless::joystick1/2 are dangling pointers since joystick1 joystick2 are freed
    }

UB while loading Vec<bool>

let mut x:T = unsafe { std::mem::uninitialized() };

impl<T: Savable> Savable for Vec<T> {
...
    fn load(&mut self, fh: &mut Read) {
        let mut len = 0usize;
        len.load(fh);
        self.truncate(0);
        self.reserve(len);
        for i in 0..len {
            let mut x:T = unsafe { std::mem::uninitialized() };
            x.load(fh);
            self.push(x);
        }
}

In case of Vec<bool> we got:

let mut x:bool = unsafe { std::mem::uninitialized() };

Which is UB by definition: https://doc.rust-lang.org/reference/behavior-considered-undefined.html

See comment rust-lang/rust#53491 (comment)

Error on nightly Rust

Building with nightly instead of stable produces:

error[E0597]: `texture_creator` does not live long enough
   --> src\main.rs:96:32
    |
96  |     let mut texture = Box::new(texture_creator.create_texture(
    |                                ^^^^^^^^^^^^^^^ borrowed value does not live long enough
...
142 |         texture: &mut *texture,
    |                  ------------- cast requires that `texture_creator` is borrowed for `'static`
...
179 | }
    | - `texture_creator` dropped here while still borrowed

I am not sure why this is an error in nightly but not in stable...

Anyway, what it's complaining about is this: as main ends, texture_creator will be freed, and then GLOBAL_STATE will be holding invalid memory; any destructors that run after texture_creator is freed could access that invalid memory.

Ideally, GLOBAL_STATE would use lazy_static, I think. Not 100% sure how much contortion that would take.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.