Ml-agents: Compilation issues with 3D Ball example, unsafe code

Created on 1 Jan 2019  Â·  20Comments  Â·  Source: Unity-Technologies/ml-agents

I'm trying to compile and run the 3D Ball example, but I get the following compilation errors:

Assets\ML-Agents\Scripts\InferenceBrain\TFSharpInferenceEngine.cs(105,43): error CS0227: Unsafe code may only appear if compiling with /unsafe. Enable "Allow 'unsafe' code" in Player Settings to fix this error.
Assets\ML-Agents\Scripts\InferenceBrain\TFSharpInferenceEngine.cs(109,43): error CS0227: Unsafe code may only appear if compiling with /unsafe. Enable "Allow 'unsafe' code" in Player Settings to fix this error.

When I allowed unsafe, Unity would crash after about a minute or so. I know there was another issue opened that had the same issue, but the solution to that was to change the .gitignore file, and those changes are already present in mine.

Also, this may or may not be related, but when I click on the 3DBallLearning.asset file under 3DBall/Brains, I get a warning saying I need to install TensorflowSharp and add the ENABLE_TENSORFLOW flag. I had already imported the 0.5 version of TensorflowSharp and added the flag, so I don't know why this is still appearing. Could somebody please help with these two issues? Thanks in advance.

help-wanted

Most helpful comment

had the same issue with Unity 2018.2.7f1 on Ubuntu 18.04.

Fixed it by going to
Edit->Project Settings->Player
Check the inspector window and expand 'Other Settings.' Go to Configuration where you set 'ENABLE_TENSORFLOW.' Right below it, there's "Allow 'unsafe' Code". Check the box if it isn't.

This worked for me.

All 20 comments

make sure you install tensorflow-sharp afterwards . This is always my main issue while debugging newer versions of ML-Agents

-----Original Message-----
From: syigzaw notifications@github.com
To: Unity-Technologies/ml-agents ml-agents@noreply.github.com
Cc: Subscribed subscribed@noreply.github.com
Sent: Tue, Jan 1, 2019 3:00 pm
Subject: [Unity-Technologies/ml-agents] Compilation issues with 3D Ball example, unsafe code (#1553)

I'm trying to compile and run the 3D Ball example, but I get the following compilation errors:AssetsML-AgentsScriptsInferenceBrainTFSharpInferenceEngine.cs(105,43): error CS0227: Unsafe code may only appear if compiling with /unsafe. Enable "Allow 'unsafe' code" in Player Settings to fix this error.
AssetsML-AgentsScriptsInferenceBrainTFSharpInferenceEngine.cs(109,43): error CS0227: Unsafe code may only appear if compiling with /unsafe. Enable "Allow 'unsafe' code" in Player Settings to fix this error.When I allowed unsafe, Unity would crash after about a minute or so. I know there was another issue opened that had the same issue, but the solution to that was to change the .gitignore file, and those changes are already present in mine.Also, this may or may not be related, but when I click on the 3DBallLearning.asset file under 3DBall/Brains, I get a warning saying I need to install TensorflowSharp and add the ENABLE_TENSORFLOW flag. I had already imported the 0.5 version of TensorflowSharp and added the flag, so I don't know why this is still appearing. Could somebody please help with these two issues? Thanks in advance.—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub, or mute the thread.

Maybe I'm missing something, but what exactly do you mean by install? I ran the downloaded Unity TensorflowSharp plugin file and it put a bunch of files in the project I had open. Then I added the ENABLE_TENSORFLOW flag. Do I need to do anything after this?

Restart computer and Unity? Check if unsafe is really allowed. My TS is from https://s3.amazonaws.com/unity-ml-agents/0.5/TFSharpPlugin.unitypackage.

I restarted my computer and Unity, and it still occurs. Also, that link is where my TensorflowSharp is from as well. If you check those two lines in the file mentioned in the above errors, they're both function signatures that are marked unsafe. I have no idea why that's there. When I take out the unsafes, I get an error saying
Assets\ML-Agents\Scripts\InferenceBrain\TFSharpInferenceEngine.cs(109,43): error CS0214: Pointers and fixed size buffers may only be used in an unsafe context
So I don't think removing the unsafes is the answer.

I dont want you to remove unsafe, also pointers are defined to be only in unsafe. But have you really allowed unsafe code checkbox in edit --> player settings?

Yup, I clicked that. It's right under the scripting define symbols. Whenever I click that, the whole editor crashes after a minute or so.

Same Here..

@syigzaw / @superjayman - what version of ML-Agents and Unity are you using?

Unity: 2018.3.0f2
ML-Agents: 0.6

Same for me ^^

Try it with Unity 2018.2.20f

I just tried it with Unity 2018.2.20f1 and the same thing happened.

Same here on Unity 2018.2.7f1 as well as 2018.3.0f2, ml-agents 0.6 on Ubuntu 16.04

had the same issue with Unity 2018.2.7f1 on Ubuntu 18.04.

Fixed it by going to
Edit->Project Settings->Player
Check the inspector window and expand 'Other Settings.' Go to Configuration where you set 'ENABLE_TENSORFLOW.' Right below it, there's "Allow 'unsafe' Code". Check the box if it isn't.

This worked for me.

I also ran into this problem. I was not able to get this working with 2018.3.1f1 or 20128.2.20r1 (even with allowing 'unsafe' code), but finally was successful with 2017.4.18f.

Going back to Unity 2017.4.10f1 worked (2017.4.18f not available on Linux)

Allowing 'unsafe code' was what seemed to crash Unity on 2018.* versions on my machine

I just tried this with Unity 2018.2.0f2, and with ML-Agents 0.4. This worked for me, and I was able to train the 3D Ball model. When I tried with the same Unity and ML-Agents 0.6, Unity didn't crash after I allowed unsafe code, but it did crash after I tried to train the brain externally. I followed the instructions here:
https://github.com/Unity-Technologies/ml-agents/blob/master/docs/Basic-Guide.md

After I clicked the play button, Unity crashed.

Same problem here, looks like something about ML Agents 0.6 / TensorFlowSharp 0.5.0 is incompatible with Unity 2018.x (?)

Unity Version 2018.3.5f1
TensorFlowSharp Plugin: 0.5.0
ML Agents: Github commit d3f9fd63043f1c82790d3fe35ee07dc5ed1232b9 (Jan 11, 2019)

Thanks for the input everyone. We've updated ML-Agents to v0.7 which changes our inference engine. This should fix this issue. Please give it a go and submit a new issue if you continue facing issues (which should be different from the ones here).

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

mattinjersey picture mattinjersey  Â·  3Comments

Hongsungchan picture Hongsungchan  Â·  3Comments

MarkTension picture MarkTension  Â·  3Comments

Procuste34 picture Procuste34  Â·  3Comments

DVonk picture DVonk  Â·  3Comments