-
Notifications
You must be signed in to change notification settings - Fork 194
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
Support for external main loop #391
Support for external main loop #391
Conversation
Thanks for setting up the draft, it would be really nice functionality to have. I'd love to find a way to restructure Something like this?
For further control, we could also add extension points that execute user-code within I'm open to callbacks for custom crash handlers and logging. |
I moved the things to bs::CoreApplication. I think I also figured out the crashing on shutdown. I added an extra frame render call to the shutdown, which seems to have solved the crashing there. So it might have been that I was destroying stuff after the final frame, and then on bsf shutdown the objects were attempted to be destroyed again. For disabling the crash handler, would adding parameters for configuring callbacks to |
Yep that looks like what I imagined. It feels that one extra cycle before shutdown should be unnecessary, there might be something else causing the crash, but I didn't have time to take a closer look. I don't think I'm doing an extra cycle in the existing loop. Adding callbacks to |
I've now done the callbacks I'd like to have. Is this an acceptable approach? I can move the final render frame out of the end loop method (and into my code) if that would be better. |
/** Struct for holding crash handler settings */ | ||
struct CrashHandlerSettings | ||
{ | ||
/** Called at the start of a when a windows SEH exception is started to be handled. Return true to skip default action */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Comment seems to imply this is windows only
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Whoops, I forgot to write the first part of the sentence, it should say both for normal exception handling and SEH.
const String& description, | ||
const String& function, | ||
const String& file, | ||
UINT32 line)> onBeforeReportCrash; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Members should have 'm' prefix (mOnBeforeReportCrash
) and be listed before static memebers (i.e. before sFatalErrorMsg
). Same goes for the two below.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, can't we just keep a copy of CrashHandlerSettings here? Saves copying the fields and the doc comments as well.
* Called after the crash callstack is written to log. Return true to skip writing to file and doing | ||
* further other on crash actions | ||
*/ | ||
std::function<bool()> onCrashPrintedToLog; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd prefer this be named onAfterReportCrash, to be more consistent with the naming + printing to log might not happen, we might just save a dump file, in which case its inacurrate.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't want BSF to actually write any log files. So I want this callback to be between the print to log and save log to file calls in the crash handler. The name change wouldn't completely capture the entire meaning.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense.
Crash handler callback stuff looks good, clean code and I like the addition of the settings object. I made some comments on minor issues. Regarding the log callback, I don't think we should be adding a callback to |
I'll address the other comments in a bit. But I don't think the current Debug callback is sufficient. It looks like that it doesn't immediately trigger, which is something I need in saving my custom log on crash. Also it doesn't have a way to suppress the default actions. Though moving the immediate callback to bs::Debug should work. |
I made some changes. |
@@ -75,7 +75,7 @@ namespace bs | |||
// Ensure all errors are reported properly | |||
CrashHandler::startUp(desc.crashHandling); | |||
if(desc.logCallback) | |||
gDebug().getLog().setLogCallback(desc.logCallback); | |||
gDebug().setLogCallback(desc.logCallback); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps it would be better to make this an Event
? This way multiple things can subscribe to it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah but I guess you need the return value. So that's not going to work.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I want to skip the default thing. And it looks like the Event class can't return any callback result values.
@@ -98,6 +105,8 @@ namespace bs | |||
private: | |||
UINT64 mLogHash = 0; | |||
Log mLog; | |||
/** @copydoc START_UP_DESC::logCallback */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We shouldn't copy-doc from START_UP_DESC
. Anything in bsfUtility
shouldn't reference classes in higher 'layers' (i.e. bsfEngine
).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What would be the alternative, have the copydoc going the other way?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can't copy-doc private stuff. I'd not document the private field at all since its setter is documented anyway.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I removed the documentation on it.
void CoreApplication::endMainLoop() | ||
{ | ||
// One more frame needs to be rendered here to not crash if the outer main loop has done stuff since the last frame. | ||
runMainLoopFrame(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This bit is still bothering me. What exactly happens when you remove it? Does the crash happen with normal bsf code or only your app (e.g. does it happen in examples)? If it's only your code then I'd be happiest we removed it here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I removed that call. I'm sure though that if anyone uses the single frame functions like I do (with releasing objects after the last frame), they are going to need to have the extra frame added in their code.
If anyone else gets crashes "when doing it correctly" then they need to add one extra runMainLoopFrame call before calling endMainLoop
Thanks for making the changes. Merged. |
thanks |
This is a basic alternative class to Application with support for external main loop (https://discourse.bsframework.io/t/using-bf-framework-as-a-graphics-library/432?u=hhyyrylainen). This isn't yet in the best shape, so I'm making this a draft.
This basically has two issues:
waitUntilFrameFinished
before shutdown, but it still crashes often on shutdown (not always, though). The crash handler output is posted below.And one extra feature I'd like (but I'm unsure how it should be done):
Crash on shutdown: