Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

unsafe code using visual studio

Discussion in 'Scripting' started by ghiboz, Sep 29, 2015.

  1. ghiboz

    ghiboz

    Joined:
    Sep 7, 2012
    Posts:
    465
    hi all!
    I've got this code:
    Code (CSharp):
    1. public class CSm
    2. {
    3.     private float* nMemory;
    4.     public CSm()
    5.     {
    6.  
    7.     }
    8. }
    and it gives me the error:

    Code (csharp):
    1. Assets/Scripts/CSm.cs(10,18): error CS0214: Pointers and fixed size buffers may only be used in an unsafe context
    reading the docs i've added to the player settings the unsafe symbol but doesn't work..


    any ideas?
     
  2. A.Killingbeck

    A.Killingbeck

    Joined:
    Feb 21, 2014
    Posts:
    483
  3. ghiboz

    ghiboz

    Joined:
    Sep 7, 2012
    Posts:
    465
    thanks, but if I use this:
    Code (CSharp):
    1. private unsafe float* nMemory;
    the error is this:
    Code (csharp):
    1. Assets/Scripts/CSm.cs(10,27): error CS0227: Unsafe code requires the `unsafe' command line option to be specified
     
  4. Ippokratis

    Ippokratis

    Joined:
    Oct 13, 2008
    Posts:
    1,521
  5. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    10,507
  6. ghiboz

    ghiboz

    Joined:
    Sep 7, 2012
    Posts:
    465
    thanks all!!
    @Tautvydas Zilys I've tried with the smcs.rsp but the error is still present...
     
  7. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    10,507
    Try naming it gmcs.rsp - the file name depends on .NET profile settings in player settings.
     
  8. ghiboz

    ghiboz

    Joined:
    Sep 7, 2012
    Posts:
    465
    thanks again @Tautvydas Zilys
    here is my profile settings...

    where is the profile setting?
     
  9. Tongie

    Tongie

    Joined:
    Sep 19, 2012
    Posts:
    90
    Its not working? i tried both file naming do i have to place it somewhere special?
     
  10. ghiboz

    ghiboz

    Joined:
    Sep 7, 2012
    Posts:
    465
    i've created a .NET dll with the unsafe code and works