Bill,
That could be it! I am a new J user and sometimes this stuff can bite when
you least expect it!
Forgive the length of this email but I am learning and want to make sure I
am being understood as well as my lack of J time permits...

I add this code to my verb:
smoutput '--- $ on width ww rw'
smoutput $ width
smoutput $ ww
smoutput $ rw

and the output as it dies:
--- $ on width ww rw

1
1
┌─┬────┬───┬──┬────────┬─────┬───┬──────────┐
│0│1024│768│32│16711680│65280│255│4278190080│
└─┴────┴───┴──┴────────┴─────┴───┴──────────┘
|domain error: sdl_creatergbsurface
|   sfc=:    sdl_creatergbsurface args

What's the difference then between unboxing 'y' as
'width height'=.y
and unpacking a boxed response from a cd call?
'rw rh' =: 2 }. sdl_getrendereroutputsize appr;(,_1);(_1)

Calling the function that generates the renderer size returns a boxed list
as described in the foreign call docs:
   sdl_getrendereroutputsize appr;(,_1);(,_1)
┌─┬───────────────┬────┬───┐
│0│140510164262000│1024│768│
└─┴───────────────┴────┴───┘
The 0 is the 'n' in the declaration, the long is the appr pointer address,
and finally the 1024 and 768 are the two values I want assigned to rw and
rh.
I thought that by first dropping the initial two elements I'd be home dry,
doing this however:

   $ 2{::sdl_getrendereroutputsize appr;(,_1);(,_1)
1

Seems to indicate that the actual return value./.....AHHHHHHHHHHHH!!!!!!!!!
I THINK THAT'S IT!!!
I was going to say that it looks like the actual boxed value is an array
with one element when the lights came on...
it MUST be an array of one element because the declaration is *i and that
implies an array of integers
Is that reasoning correct??? So anywhere a C function expects the address
of a scalar, even though in C I can use &intFoo, the FFI code in J (which I
have spent about an hour poring over last night but it's very dense and
convoluted) will always turn it into an array.
That would seem to be what is happening and with hindsight (as always) it
makes perfect sense now.

I think I've been very LUCKY to get as far as I have if that's the case..I
have these lines:
cxm=: rw % ww
cym=: rh % wh

Which work BUT not as I was assuming, J is after all happy to deal with
arrays, my poor brain isn't yet it would seem! :)
I bet if I check the type of cxm and cym they are arrays too not
scalars...yes, they are indeed not scalars!!
$ cxm
1
$ cym
1

I foolishly thought Haskell would be the hardest language I ever learned to
code with; I never liked the word monad in that context....!

Thanks
Sean


On Fri, 27 Nov 2020 at 13:05, bill lam <bbill....@gmail.com> wrote:

> probably your width and height are not scalar but singleton array. you can
> check them with monad $ .
>
> On Fri, Nov 27, 2020, 8:00 PM emacstheviking <obji...@gmail.com> wrote:
>
> > Given these working external function declarations:
> >
> > SDL_GetWindowSize n x *i *i
> > SDL_GetRendererOutputSize n x *i *i
> > SDL_CreateRGBSurface > x i i i i i i i i
> >
> > then these two calls:
> >
> > 'ww wh'=:2}.sdl_getwindowsize appw;(,_1);(,_1)
> > 'rw rh'=:2}.sdl_getrendereroutputsize appr;(,_1);(,_1)
> >
> > work and produce values of 1024 for ww and rw, and 768 for wh and rh
> > respectively, as expected.
> > However, when creating the rgb surface it raises a domain error and I
> have
> > been tearing my hair out to understand why.
> > I have posted the full code at the end of this plea for help and
> > enlightenment.
> >
> > args=.0;width;height;32;16bff0000;16bff00;16bff;16bff000000
> > smoutput args
> > sfc=: sdl_creatergbsurface args
> >
> > cder''
> > 6 1
> >
> > yet calling it with literals or even the extracted 'y' value (a boxed
> > dimension):
> > args=.0;1024;768;32;16bff0000;16bff00;16bff;16bff000000. NB. works
> > args=.0;width;height;32;16bff0000;16bff00;16bff;16bff000000. NB. works
> >
> > I have used 3!:0 to examine the type, it is 4 (integer) in all cases
> > (ww,wh,rw,rh,width,height), ruling out those errors.
> > Thanks,
> > Sean. :|
> >
> > -- full code ---
> >
> > ugo =: 3 : 0
> > NB. testing out domain errors around sdl_creatergbsurface...
> > args =. SCREEN_X_MAX;SCREEN_Y_MAX
> > scrw =. SCREEN_X_MAX
> > scrh =. SCREEN_Y_MAX
> > sdlprep scrw;scrh
> > cairoprep''
> > urun''
> > uend^:y ''
> > )
> >
> > sdlprep =: 3 : 0
> > 'width height'=. y
> > sdl_init SDL_INIT_EVERYTHING
> > appw=:sdl_createwindow 'test window';0;0
> > ;width;height;SDL_WINDOW_SHOWN+SDL_WINDOW_ALLOW_HIGHDPI
> > appr=:sdl_createrenderer appw;_1
> > ;SDL_RENDERER_ACCELERATED+SDL_RENDERER_PRESENTVSYNC
> > 'ww wh'=:2}.sdl_getwindowsize appw;(,_1);(,_1)
> > 'rw rh'=:2}.sdl_getrendereroutputsize appr;(,_1);(,_1)
> > cxm=: rw % ww
> > cym=: rh % wh
> > smoutput 'window: ', (":appw), 'renderer:', (":appr)
> > smoutput 'requested width:',(":width),' height:',(":height)
> > smoutput 'render width: ',(":rw),' height:',(":rh)
> > smoutput 'window width: ',(":ww),' height:',(":wh)
> > smoutput 'x/y multipliers:',(":cxm),'/',(":cym)
> > NB. This needs to be endian-aware at some point
> > smoutput (": (width = rw))
> > args=.0;width;height;32;16bff0000;16bff00;16bff;16bff000000
> > smoutput args
> > sfc=: sdl_creatergbsurface args
> > NB. Practice structures. PACKING!!! Show printable format name
> > pFormat=._3 ic memr (sfc+8),0,8 NB. sdl_surface->format
> > format=._2 ic memr pFormat,0,4 NB. sdl_surface->format->format
> > smoutput 'pixel format:',(psz sdl_getpixelformatname format)
> > EMPTY
> > )
> > ----------------------------------------------------------------------
> > For information about J forums see http://www.jsoftware.com/forums.htm
> >
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm
>
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to