mb.StringValue Exception on OSX

Hello Everyone,

I am converting a picture to a memoryblock for graphics in OpenGL and the following code works on Windows 10 but fails with an ‘Out of bounds Exception’ on Sierra (version 10.12) in the last line of code. Any thoughts as to what I am doing wrong?

[code] Dim Pic as New Picture(256, 256, 32)
pic.Graphics.DrawString(“hello”,10,10)
Dim textureBitmap As MemoryBlock
textureBitmap = new MemoryBlock(pic.Height * pic.Width * 4)

Dim mb as MemoryBlock
mb = Pic.GetData(picture.FormatBMP)
textureBitmap = mb.StringValue(54, pic.Heightpic.Width4) //Out of bounds exception here
[/code]

you may miscalculate the bounds.

Probably *3 and not *4.

and this line is not needed:

textureBitmap = new MemoryBlock(pic.Height * pic.Width * 4)

Thank you to both Christian and Jean-Paul for your answers.

Jean-Paul, you are correct, rerunning the program by removing 54 allows the program to work on both Windows and OSX.

Christian, the *3 would work for an RGB conversion. My apologies as I did not mention that this was an RGBA conversion which needed the *4. Thanks for your quick answer!

Hi Christian,

Thank you for mentioning this, as it has raised an issue with a difference between Windows and OSX with OpenGL. In Windows I need to implement the BGRA implementation to have the graphic appear properly, and on OSX I need to implement the BGR implementation to correctly draw the graphics.

#If TargetWindows OpenGL.glTexImage2D(OpenGL.GL_TEXTURE_2D, 0, OpenGL.GL_RGB, 256, 64, 0, OpenGL.GL_BGRA, OpenGL.GL_UNSIGNED_BYTE, glMyText) #Else OpenGL.glTexImage2D(OpenGL.GL_TEXTURE_2D, 0, OpenGL.GL_RGB, 256, 64, 0, OpenGL.GL_BGR, OpenGL.GL_UNSIGNED_BYTE, glMyText) #Endif

I am not sure why there is a difference, but there is.