bug of overflow due to IntPtr solved

This commit is contained in:
Nitload
2023-07-03 05:16:51 +08:00
parent 04b166771c
commit 2a78a60358
27 changed files with 58 additions and 66 deletions
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
+4 -3
View File
@@ -15,10 +15,11 @@ namespace StgSharp.Graphics
public unsafe class Form
{
internal IntPtr windowPtr;
internal formInfo info;
internal long windowID; //pointer to the form
internal formInfo info = new formInfo() ;
internal IntPtr shader;
internal LinkedList<Pool> allControl = new LinkedList<Pool>();
internal LinkedList<Pool> allControl;
public vec2d Size
{
+14 -15
View File
@@ -32,7 +32,7 @@ namespace StgSharp
else
{
windowPtr = glIO.internalGLcreateWindow(
width, height, tittle, monitor, (IntPtr)share.windowPtr);
width, height, tittle, monitor, (IntPtr)share.windowID);
}
@@ -44,7 +44,7 @@ namespace StgSharp
{
Form form = new Form();
form.Size = new vec2d(width, height);
form.windowPtr = windowPtr;
form.windowID = (long)windowPtr;
return form;
}
}
@@ -61,41 +61,40 @@ namespace StgSharp
/// <exception cref="Exception"></exception>
public static unsafe Form GLcreateWindow(int width, int height, string tittle, IntPtr monitor, IntPtr share)
{
Form form = new Form();
form.Size = new vec2d(width, height);
byte[] tittleCharArray = System.Text.Encoding.UTF8.GetBytes(tittle);
IntPtr windowPtr = glIO.internalGLcreateWindow(width, height, tittleCharArray, monitor, share);
form.info.name = tittleCharArray;
form.windowPtr = windowPtr;
Console.WriteLine(windowPtr);
long windowPtr = (long)glIO.internalGLcreateWindow
(width, height, tittleCharArray, monitor, share);
if ((int)windowPtr == -1 || (int)windowPtr == -2)
{
throw new Exception("Cannot create window instance!");
throw new Exception("Cannot create the form!");
}
else
{
Form form = new Form();
form.Size = new vec2d(width, height);
form.windowID = windowPtr;
return form;
}
}
public static unsafe void GLmakeContexCurrent(Form form)
{
glIO.internalGLmakeContextCurrent((IntPtr)form.windowPtr);
glIO.internalGLmakeContextCurrent((IntPtr)form.windowID);
}
public static unsafe bool GLwindowShouldClose(Form form)
{
int a = glIO.internalGLwindowShouldClose((IntPtr)form.windowPtr);
int a = glIO.internalGLwindowShouldClose((IntPtr)form.windowID);
return a != 0;
}
public static unsafe void GLswapBuffers(Form form)
{
glIO.internalGLswapBuffers((IntPtr)form.windowPtr);
glIO.internalGLswapBuffers((IntPtr)form.windowID);
}
}
+34 -26
View File
@@ -8,16 +8,8 @@ namespace StgSharp
{
internal static GraphicIOPack glIO;
private static bool isGLSet = false;
/// <summary>
/// Init an instance of OpenGL program,
/// This method should be called before other
/// graphic methods, after LoadGL method.
/// </summary>
public static void InitGL()
{
internalIO.InternalInitGL();
}
private static bool isGLADset = false;
private static bool isGLready = false;
/// <summary>
/// Load OpenGL API to StgSharp core programm,
@@ -27,7 +19,7 @@ namespace StgSharp
/// <exception cref="Exception">If run this method twice, will throw exception</exception>
public static unsafe void LoadGL()
{
if (!isGLSet)
if (!isGLADset)
{
glIO = internalIO.InternalInitGraphicApi();
}
@@ -37,6 +29,27 @@ namespace StgSharp
}
}
/// <summary>
/// Init an instance of OpenGL program,
/// This method should be called before other
/// graphic methods, after LoadGL method.
/// </summary>
public static void InitGL()
{
if (!isGLSet)
{
internalIO.InternalInitGL();
isGLready = isGLSet && isGLADset;
}
else
{
throw new Exception("Do not init GL twice");
}
}
/// <summary>
/// Attach GLFW API to GLAD,
/// this method should be called after LoadGL
@@ -44,33 +57,28 @@ namespace StgSharp
/// </summary>
/// <exception cref="Exception">The accident that program cannot attach GLFW to GLAD</exception>
public static unsafe void InitGLAD()
{
if (!isGLADset)
{
int a = internalIO.InternalInitGLAD();
if (a!=0)
if (a != 0)
{
throw new Exception("Cannot attach GLFW to GLAD!");
}
else
{
isGLready = isGLSet && isGLADset;
return;
}
}
else
{
throw new Exception("Do not init GLAD twice.");
}
}
internal static byte[] loadShaderCodeStr(string str)
{
byte[] cahrStr;
try
{
cahrStr = System.Text.Encoding.ASCII.GetBytes(str);
return cahrStr;
}
catch (Exception)
{
throw;
}
}
-2
View File
@@ -12,8 +12,6 @@ namespace StgSharp
{
private unsafe static void Main(string[] args)
{
Console.WriteLine(sizeof(int*));
Graphic.LoadGL();
Graphic.InitGL();
Graphic.InitGLAD();
@@ -124,6 +124,7 @@
<Folder Include="Graphics\" />
<Folder Include="Logic\" />
<Folder Include="Math\" />
<Folder Include="Properties\" />
</ItemGroup>
@@ -7,5 +7,5 @@ build_property.InvariantGlobalization =
build_property.PlatformNeutralAssembly =
build_property.EnforceExtendedAnalyzerRules =
build_property._SupportedPlatformList = Linux,macOS,Windows
build_property.RootNamespace = StgSharpDebug
build_property.RootNamespace = StgSharp
build_property.ProjectDir = D:\NitloadIndustry\研究项目\1-Flagship\TH2020\ProjectFile\源代码\StgSharpDebug\
@@ -47,17 +47,3 @@ STGSHARPGRAPHIC_API int initGLAD(void)
return gladLoadGLLoader((GLADloadproc)glfwGetProcAddress);
}
GLFWwindow* (*createWindow)(
int width,
int height,
const char* title,
GLFWmonitor* monitor,
GLFWwindow* share);
STGSHARPGRAPHIC_API void* getPtr(void)
{
createWindow = glfwCreateWindow;
return createWindow;
}
@@ -19,7 +19,6 @@
STGSHARPGRAPHIC_API glIOpackage loadGLApi(void);
STGSHARPGRAPHIC_API void initGL(void);
STGSHARPGRAPHIC_API int initGLAD(void);
STGSHARPGRAPHIC_API void* getPtr(void);
#endif // !SSG