~whereswaldon/gioprofiler

2dcf6a8e70e1ea3b7b69215e653c8d3ac2170ae4 — Chris Waldon 6 months ago 3217a89
feat: ensure Profile() does not panic on nil receiver.

Signed-off-by: Chris Waldon <christopher.waldon.dev@gmail.com>
1 files changed, 8 insertions(+), 2 deletions(-)

M profiling.go
M profiling.go => profiling.go +8 -2
@@ 166,8 166,11 @@ func (c *CSVTimingRecorder) Stop() error {

// Profile records profiling data from the last frame and prepares the
// capture of the next frame. Calling this method every frame is sufficient
// to profile all frames.
// to profile all frames. It will simply return if c is nil.
func (c *CSVTimingRecorder) Profile(gtx layout.Context) {
	if c == nil {
		return
	}
	var lastEventTime time.Time
	lastEventTime, c.nextEventTime = c.nextEventTime, gtx.Now
	profile.Op{Tag: c}.Add(gtx.Ops)


@@ 181,8 184,11 @@ func (c *CSVTimingRecorder) Profile(gtx layout.Context) {

// Write is a lower-level way to capture a single profile event. It should
// be used instead of the Profile method if more granular profiling control
// is desired.
// is desired. It will simply return if c is nil.
func (c *CSVTimingRecorder) Write(when time.Time, e profile.Event) error {
	if c == nil {
		return nil
	}
	var err error
	select {
	case err = <-c.errChan: