Closed Nazariglez closed 2 days ago
I don't know Nim enough to analyze the problem tbh. The error looks like it's trying to access invalid memory, or the nullptr. The main difference to the original samples seems to be the use of Nim sequences. Where do those store their data and how is lifetime of that data handled? If Nim's garbage collection or RAII-like memory management is involved, maybe the data is already freed before the makeImage() function is entered?
I thought the same. I am new to nim too. Sequences are stored in the heap as far as I know. I added some operations after the make image to keep it alive the pixels and the desc
(stored it in a independent variable), but the same result.
Then I tried changing the memory management options to refc
and none
. Both of them work with an image of 54x54 and crashes with more pixels, while orc
(the default) only work with images up to 53x53.
Last attempt, I generated an array[155*154, uint32]
manually and paste it into the code to be used as image data, and it works no matter the memory option I pass to the compiler.
My guess is that I should share this issue in the nim's forum to see if any fellow there knows what could be wrong and how to fix it.
Edit:
Tested with nim 2.0.6
and 2.0.8
Edit2: Thread in nim forum: https://forum.nim-lang.org/t/11925
@Nazariglez you give pointer to sequence object, not sequence memory. this line:
subimage: [ [ sg.Range(addr: addr data, size: width * height * 4) ] ]
should be:
subimage: [ [ sg.Range(addr: addr data[0], size: width * height * 4) ] ]
Oh wow, this works, thank you!
Would you happen to have any resources or information about why this is the case? I am checking nim-by-example and other resources, and it seems that data[0]
should access the first element in the sequence, similar to array behavior. So I am a bit lost in understanding why this is happening.
Also, this means that there is no way to pass an array and a sequence interchangeably because we need to know the type to pass data
or data[0]
. This also makes me wonder why it works with small images but not with "big" images.
I know I have a lot of questions. I am closing the issue because it is not related to sokol itself. However, if you have the time and willingness, it would be really helpful to me to know more about this. In any case, thank you so much.
I have an issue trying to render images. I am not sure what's going on because it happen using images with more than 2809 pixels... a size of 53x53 works, but no higher.
One way to test this is loading an image as:
Another is altering the texcube example to increase the size of the generated texture:
this will panic at runtime with:
I think that I am missing something, or there is a bug somewhere in nim or the sokol bindings. Does this rings any bell?
Thanks!