# CPP target crashes without any error messages

**URL:** <https://community.haxe.org/t/cpp-target-crashes-without-any-error-messages/2785>\
**Category:** Haxe\
**Tags:** haxe-cpp\
**Created:** [November 28, 2020, 11:52pm UTC](https://community.haxe.org/t/cpp-target-crashes-without-any-error-messages/2785 "2020-11-28T23:52:41Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![barisyild](https://community.haxe.org/user_avatar/community.haxe.org/barisyild/32/1376_2.png) [@barisyild](https://community.haxe.org/u/barisyild)\
**Post date:** [November 28, 2020, 11:52pm UTC](https://community.haxe.org/t/cpp-target-crashes-without-any-error-messages/2785/1 "2020-11-28T23:52:41Z")

</div>

How to detect null access on cpp target. ( **multithreading** )

**For example:**

```haxe
public static var simpleMap:Map<String, Dynamic>;

static public function main() {
	//simpleMap = new Map<String, Dynamic>();

	sys.thread.Thread.create(() -> {
		simpleMap.set("1", {
			example : null
		});
	});

	trace("OK");
	while(true)
	{

	}
}

```

There is a similar situation in my application, but I cannot find it because exception info not available.

---

<div class="post-metadata">

**Author:** ![RealyUniqueName](https://community.haxe.org/user_avatar/community.haxe.org/realyuniquename/32/10_2.png) [@RealyUniqueName](https://community.haxe.org/u/RealyUniqueName)\
**Post date:** [November 29, 2020, 9:23am UTC](https://community.haxe.org/t/cpp-target-crashes-without-any-error-messages/2785/2 "2020-11-29T09:23:11Z")

</div>

IIRC null access is not checked in release mode by default. Either add `-D HXCPP_CHECK_POINTER` define or build in debug with `--debug`.  
See this doc for other flags: [hxcpp/Defines.md at 531303dbf0fef34c2788b3a6be7372a70c77d919 · HaxeFoundation/hxcpp · GitHub](https://github.com/HaxeFoundation/hxcpp/blob/531303d/docs/build_xml/Defines.md)

---

<div class="post-metadata">

**Author:** ![barisyild](https://community.haxe.org/user_avatar/community.haxe.org/barisyild/32/1376_2.png) [@barisyild](https://community.haxe.org/u/barisyild)\
**Post date:** [November 29, 2020, 9:40am UTC](https://community.haxe.org/t/cpp-target-crashes-without-any-error-messages/2785/3 "2020-11-29T09:40:47Z")

</div>

I updated the example, null exception does not show when it is a multi threading.

```haxe
public static var simpleMap:Map<String, Dynamic>;

static public function main() {
	//simpleMap = new Map<String, Dynamic>();

	sys.thread.Thread.create(() -> {
		simpleMap.set("1", {
			example : null
		});
	});

	trace("OK");
	while(true)
	{

	}
}

```

---

<div class="post-metadata">

**Author:** ![barisyild](https://community.haxe.org/user_avatar/community.haxe.org/barisyild/32/1376_2.png) [@barisyild](https://community.haxe.org/u/barisyild)\
**Post date:** [November 29, 2020, 9:46am UTC](https://community.haxe.org/t/cpp-target-crashes-without-any-error-messages/2785/4 "2020-11-29T09:46:51Z")

</div>

**Non-Multi Threaded Source Code:**

```haxe
class Main {
    public static var simpleMap:Map<String, Dynamic>;

    static public function main() {
        //simpleMap = new Map<String, Dynamic>();

        simpleMap.set("1", {
            example : null
        });

        trace("OK");
        while(true)
        {

        }
    }
}

```

**Output:**

> Called from hxcpp::\_\_hxcpp\_main  
> Called from Main::main Main.hx line 7  
> Error : Null Object Reference

* * *

**Multi Threaded Source Code:**

```haxe
class Main {
    public static var simpleMap:Map<String, Dynamic>;

    static public function main() {
        //simpleMap = new Map<String, Dynamic>();
        
        sys.thread.Thread.create(() -> {
            simpleMap.set("1", {
                example : null
            });
        });
        
        trace("OK");
        while(true)
        {

        }
    }
}

```

\ ***Crashing without any output.**

---

<div class="post-metadata">

**Author:** ![hypergeome](https://community.haxe.org/user_avatar/community.haxe.org/hypergeome/32/1907_2.png) [@hypergeome](https://community.haxe.org/u/hypergeome)\
**Post date:** [May 31, 2022, 9:09am UTC](https://community.haxe.org/t/cpp-target-crashes-without-any-error-messages/2785/5 "2022-05-31T09:09:22Z")

</div>

I am also looking for a solution to this. I have a thread running and randomly crash and I have no clue on what or where that cause it. Is there any news on this yet?
