Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[brl.pixmap] Handling "noDebug" - with still catching "null objects" #315

Open
GWRon opened this issue Mar 21, 2024 · 0 comments
Open

[brl.pixmap] Handling "noDebug" - with still catching "null objects" #315

GWRon opened this issue Mar 21, 2024 · 0 comments

Comments

@GWRon
Copy link
Contributor

GWRon commented Mar 21, 2024

Hotcakes at the discord channel had some issues with MaskPixmap - as they did not check if the passed pixmap is a valid one.

As brl.pixmap (pixmap.bmx) defines MaskPixmap as noDebug a debug build does not catch it.

I am now looking for "proper" ways to have "valid object checks" (in debug builds only...) while keeping the performance benefit of "nodebug" in debug builds.

I came up with this:

Function MaskPixmap:TPixmap( pixmap:TPixmap,mask_red,mask_green,mask_blue )
    assert pixmap Else "pixmap is null"
    Return __MaskPixmap( pixmap, mask_red, mask_green, mask_blue)
End Function

Function __MaskPixmap:TPixmap( pixmap:TPixmap,mask_red,mask_green,mask_blue ) Inline NoDebug
    Local tmp:TPixmap=pixmap
    If tmp.format<>PF_RGBA8888 tmp=tmp.Convert( PF_RGBA8888 )
    
    Local out:TPixmap=CreatePixmap( tmp.width,tmp.height,PF_RGBA8888 )
    ...
    'rest of the original MaskPixmap function

Inline will make the GCC marking the function able to get inlined (so we should get rid of the "function call" overhead)
NoDebug will keep the for-loops in the original function logic "fast" in debug builds.

Another option might be to use the hackish

?debug
'!direct-c-code`
?

approach to build an assert-style thingy in C - which is only existing in "debug builds" then.

I know - only 6 functions in brl and pub.mod are "nodebug" (4 in pixmap and 2 in freeprocess) so maybe simply making them "debug" again is the way to go - but I am trying to find a way to improve the situation for "debug builds" (maybe some other code could benefit from a "nodebug" too.. )

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant