NullPointerError signals are useful and here is why we should have

ryuukk_ ryuukk.dev at gmail.com
Mon Oct 23 20:53:04 UTC 2023


I use DLL and i do hotreload in my engine

I have a single file module that solve this: 
https://github.com/ryuukk/backtraced/

Works in both linux/windows


I setup my signal handler this way, very simple:

```D

version(DLL) export extern(C) void on_reload(State* state) {
     LINFO("reloaded");

     debug rt_register_crash_handler();
}

```

And this example code in the DLL:

```D
         int* test = null;
         *test = 5;
```


Will give me this:

```
-------------------------------------------------------------------+
Received signal 'exception' (3221225477ll)
-------------------------------------------------------------------+
C:\dev\kdom\projects\game\app.d:144 - game.app.on_tick
C:\dev\kdom\projects\game\app.d:144 - game.app.on_tick
C:\dev\kdom\projects\game\app.d:144 - rt_register_crash_handler
C:\dev\kdom\projects\game\app.d:144 - BaseThreadInitThunk
C:\dev\kdom\projects\game\app.d:144 - RtlUserThreadStart
make: *** [makefile:36: game-run] Error 2816
```

I now know where exactly the code failed and i can fix it

```D
version(DLL) export extern(C) void on_tick(State* state) {

     if (state.engine.input.is_key_just_pressed(Key.KEY_SPACE))
     {
         int* test = null;
         *test = 5;
     }
}
```



I think someone made a PR to have something similar already, but 
i forgot where (phobos or druntime)




More information about the Digitalmars-d mailing list