benefit of pointer checking of cairo context

codekiddy

What happens if we do not check if cairo context exists and what happens if returning false, for example:

bool MyClass::on_draw(const Cairo::RefPtr<Cairo::Context>& cr)
{
      if ( !cr) return false;  // what realy happens when we return false?
      // is the function called once again?
}

// approach 2
bool MyClass::on_draw(const Cairo::RefPtr<Cairo::Context>& cr)
{
      // do stuff
      return true;  // works just fine without checking so why to check??
}

What is the benefit and why would one check there is a context?

What happens if returning false?

eerorika

This has documentation for virtual bool Gtk::Widget::on_draw(const::Cairo::RefPtr<::Cairo::Context>& cr). I'm assuming, you're overriding that or something similar. The documentation doesn't say anything about the return value, but states it's the default handler of Gtk::Widget::signal_draw(). Here's a quote from that documentation:

Returns

true to stop other handlers from being invoked for the event. % false to propagate the event further.

If cr doesn't point to anything, then there's probably no point in invoking further handlers of the draw event. Then again, all handlers that actually use cr should probably check it anyway, so I don't think cheking here is necessary. If you have a lot of handlers, returning true when none of them can work may reduce a bit of overhead. I'm guessing that the stopping of events is more useful for controlling the event flow on user action rather than the draw event.

Returning false only if cr doesn't point to anything seems weird to me. Returning true without checking should prevent other handlers, so that's a bit strange also.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Checking if path is simple and closed using cairo

Null pointer exception when checking for permission with android.content.Context.checkPermission

GCC __builtin_expect checking pointer nullability of temporary during constexpr context results in strange run time behavior

Segmentation fault rendering text to cairo context

Where is the cairo context object cr declared?

Access to Cairo context 'cr' in GTK window

Is there any benefit of checking typeof a === "undefined" instead of a === undefined?

Django is there a benefit of checking every view with `method=='POST':`

Checking for Null Pointer in Ada

Is there a benefit to using reference_wrapper on a pointer vs passing the pointer by reference?

Context null Pointer

optimize function pointer checking in loop

Validation context not checking Validation Attributes

How to create Cairo Context for drawing in code with Gtk Sharp and C#

How to change cairo context source color for grayscale images

What is the benefit of using a context mananger with multiprocessing.Manager?

What benefit to get functions provide in the context of Angular 4 Components?

Determine context based on instruction pointer

Java null pointer exception after checking if null

Is there a ?. operator for Java to perform null pointer checking?

Checking for NULL pointer in C/C++

Checking NULL Pointer In C Doesn't Work

C - Segmentation fault when checking if a pointer is NULL

Checking if a type is a struct or pointer at compile time in C?

Spell checking program using pointer arrays

Checking if my array of pointer string is an integer

Kotlin null pointer when checking for null state

checking the context of a .txt file in python: True, False

Type checking variables on the sanic context object?

TOP Ranking

  1. 1

    Failed to listen on localhost:8000 (reason: Cannot assign requested address)

  2. 2

    Loopback Error: connect ECONNREFUSED 127.0.0.1:3306 (MAMP)

  3. 3

    How to import an asset in swift using Bundle.main.path() in a react-native native module

  4. 4

    pump.io port in URL

  5. 5

    Compiler error CS0246 (type or namespace not found) on using Ninject in ASP.NET vNext

  6. 6

    BigQuery - concatenate ignoring NULL

  7. 7

    ngClass error (Can't bind ngClass since it isn't a known property of div) in Angular 11.0.3

  8. 8

    ggplotly no applicable method for 'plotly_build' applied to an object of class "NULL" if statements

  9. 9

    Spring Boot JPA PostgreSQL Web App - Internal Authentication Error

  10. 10

    How to remove the extra space from right in a webview?

  11. 11

    java.lang.NullPointerException: Cannot read the array length because "<local3>" is null

  12. 12

    Jquery different data trapped from direct mousedown event and simulation via $(this).trigger('mousedown');

  13. 13

    flutter: dropdown item programmatically unselect problem

  14. 14

    How to use merge windows unallocated space into Ubuntu using GParted?

  15. 15

    Change dd-mm-yyyy date format of dataframe date column to yyyy-mm-dd

  16. 16

    Nuget add packages gives access denied errors

  17. 17

    Svchost high CPU from Microsoft.BingWeather app errors

  18. 18

    Can't pre-populate phone number and message body in SMS link on iPhones when SMS app is not running in the background

  19. 19

    12.04.3--- Dconf Editor won't show com>canonical>unity option

  20. 20

    Any way to remove trailing whitespace *FOR EDITED* lines in Eclipse [for Java]?

  21. 21

    maven-jaxb2-plugin cannot generate classes due to two declarations cause a collision in ObjectFactory class

HotTag

Archive