19 Jun '13 - 12:47 *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
 
   Home   Help Search Login Register  
Pages: [1]
  Reply  |  Print  
Author Topic: BASS Vector3 crash  (Read 448 times)
BulleTTime
Posts: 28


« on: 29 Feb '12 - 20:03 »
Reply with quoteQuote

Hi, Im creating a .net wrapper for unity. When i try to implement 3d positions i crash when i send a struct with floats higher than zero. Anyone knows why?

This is my code:


using System;
using System.Collections.Generic;

using System.Text;
using System.Runtime.InteropServices;

using MyType = System.Int64;


namespace bt
{
    public class bass
    {

        public struct BASS_3DVECTOR
        {
            public float x, y, z;

           
        }

        public enum channelSettings
        {
        BASS_ATTRIB_EAXMIX = 4,
        BASS_ATTRIB_FREQ = 1,
        BASS_ATTRIB_MUSIC_AMPLIFY,
        BASS_ATTRIB_MUSIC_BPM,
        BASS_ATTRIB_MUSIC_PANSEP,
        BASS_ATTRIB_MUSIC_PSCALER,
        BASS_ATTRIB_MUSIC_SPEED,
        BASS_ATTRIB_MUSIC_VOL_CHAN,
        BASS_ATTRIB_MUSIC_VOL_GLOBAL,
        BASS_ATTRIB_MUSIC_VOL_INST,
        BASS_ATTRIB_NOBUFFER,
        BASS_ATTRIB_PAN = 3,
        BASS_ATTRIB_VOL = 2

        }
        public enum channelTags
        {
            BASS_TAG_ICY = 4,
            BASS_TAG_META = 5,
            BASS_TAG_HTTP = 3,
            BASS_TAG_OGG = 2
        }
        public enum syncTypes {
            BASS_SYNC_META = 4
        }
        public enum initFlags
        {
            BASS_DEVICE_3D = 4
        }

        public enum flags
        {
            BASS_DEFAULT = 0,
            BASS_SAMPLE_MONO = 2,
            BASS_SAMPLE_3D = 8


        }
        public enum test
        {
            BASS_CONFIG_DEV_BUFFER
        }
        public enum configs
        {
            BASS_CONFIG_NET_PLAYLIST = 21,
            BASS_CONFIG_BUFFER,
            BASS_CONFIG_DEV_BUFFER

        }
     
[DllImport("bass.dll")]

public static extern bool BASS_ChannelSet3DPosition(int stream, BASS_3DVECTOR pos, BASS_3DVECTOR pos1, BASS_3DVECTOR pos2);


public static bool set3DPosition()
        {
            BASS_3DVECTOR pos;

            pos.x = 0f;
            pos.y = 0f;
            pos.z = 0f;

            pos.x = 1f; //crash

            bool test = BASS_Set3DPosition(pos, pos, pos, pos);
            return test;
        }


public static int stream;
        public static int play(string url)
        {

            if (BASS_Init(-1, 44100, initFlags.BASS_DEVICE_3D, IntPtr.Zero, IntPtr.Zero))
            {

                BASS_PluginLoad("bass_aac.dll", 0);

                BASS_SetConfig(configs.BASS_CONFIG_NET_PLAYLIST, 1);


                stream = BASS_StreamCreateURL(url, 0, flags.BASS_SAMPLE_3D | flags.BASS_SAMPLE_MONO, 0, 0);




                if (stream != 0)
                {

                    BASS_ChannelPlay(stream, false);


                    return stream;
                }
                else
                {
                    return 1;
                }


            }
            else
            {
                return 2;
            }
        }

    }
}
Logged
Ian @ un4seen
Administrator
Posts: 15363


« Reply #1 on: 1 Mar '12 - 15:57 »
Reply with quoteQuote

I guess it is a "marshalling" issue in passing your managed BASS_3DVECTOR structure to the unmanaged BASS.DLL, but I'm not a .Net user myself, so I'm afraid I can't advise on the correct way to do it. Are you sure you can't just use BASS.Net instead of rolling your own .Net wrapper?
Logged
BulleTTime
Posts: 28


« Reply #2 on: 1 Mar '12 - 17:12 »
Reply with quoteQuote

no i cant use the .Net dll as i cant register is, because it then conflicts with the Unity3d System.core when i use BassNet namespace. I get a ambiguous warning and because of that a compile error within unity

I use this to declare the function:

[DllImport("bass.dll")]
public static extern bool BASS_Set3DPosition( BASS_3DVECTOR pos, BASS_3DVECTOR vel, BASS_3DVECTOR front, BASS_3DVECTOR top);

How should it receive the 3d positions actually?
Logged
Ian @ un4seen
Administrator
Posts: 15363


« Reply #3 on: 5 Mar '12 - 15:58 »
Reply with quoteQuote

BASS_Set3DPosition expects to receive pointers to the BASS_3DVECTOR structures.
Logged
radio42
Posts: 4030


« Reply #4 on: 6 Mar '12 - 09:14 »
Reply with quoteQuote

you might try this:
[StructLayout(LayoutKind.Sequential, CharSet=CharSet.Auto)]
[Serializable]
public sealed class BASS_3DVECTOR
{
public float x = 0f;
public float y = 0f;
public float z = 0f;

public BASS_3DVECTOR()
{
}

public BASS_3DVECTOR(float X, float Y, float Z)
{
x = X;
y = Y;
z = Z;
}
}

[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool BASS_Set3DPosition([In]BASS_3DVECTOR pos, [In]BASS_3DVECTOR vel, [In]BASS_3DVECTOR front, [In]BASS_3DVECTOR top);
Logged
BulleTTime
Posts: 28


« Reply #5 on: 7 Mar '12 - 18:05 »
Reply with quoteQuote

No more crashes with that. Thanks!
Logged
Pages: [1]
  Reply  |  Print  
 
Jump to:  

Powered by SMF 1.1.18 | SMF © 2013, Simple Machines