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

Fix simPlotPoints causing crash randomly #2963

Merged
merged 1 commit into from
Sep 2, 2020

Conversation

rajat2004
Copy link
Contributor

@rajat2004 rajat2004 commented Aug 23, 2020

Running DrawDebugPoint on GameThread seems to fix the problem

Script -

import airsim

client = airsim.VehicleClient()

points = 10000
for i in range(points):
    client.simPlotPoints(points=[airsim.Vector3r(x_val=float(0), y_val=float(0), z_val=float(0))],
                        color_rgba=[1.0, 0.0, 0.0, 1.0], size=10, duration=-1, is_persistent=True)

Without running on game thread specifically, it runs generally for 100 or even 1k calls, but always crashes when using 10k calls.
If this does fix the problem, then will probably need to update all the plot APIs

Thanks to @TomAvrech for reporting the issue and testing!
Fixes #2959

TODO:

  • Make similar changes for all APIs
  • Add some example scripts for plotting APIs (Probably as a future PR)

A question arose as to why something like this isn't required for DrawDebugPoints in Lidar, Distance Sensor (Maybe cause Tick runs in game thread)

@madratman
Copy link
Contributor

Good catch, I think this should fix it.
This is the correct reasoning for lidar drawdebugpoints to not crash - (Maybe cause Tick runs in game thread). Lidar's drawdebugpoint is called in every tick in simmodeworldbase.

@rajat2004
Copy link
Contributor Author

Great, thanks for the review @madratman
If you want, this PR can be merged as is I think, did want to add some examples and documentation but haven't started on them right now, probably as another PR

Fixes random crashes on usage
Plus some general cleanup
@rajat2004
Copy link
Contributor Author

I've added some more cleanups like creating the color object only once rather than every time, passing simple data-types like bool, float by value, style fixes

Comment on lines -344 to +355
for (int idx = 0; idx < points.size(); idx += 2)
{
DrawDebugLine(simmode_->GetWorld(), simmode_->getGlobalNedTransform().fromGlobalNed(points[idx]), simmode_->getGlobalNedTransform().fromGlobalNed(points[idx+1]), color.ToFColor(true), is_persistent, duration, 0, thickness);
}
UAirBlueprintLib::RunCommandOnGameThread([this, &points, &color, thickness, duration, is_persistent]() {
for (int idx = 0; idx < points.size()-1; idx += 2) {
DrawDebugLine(simmode_->GetWorld(),
simmode_->getGlobalNedTransform().fromGlobalNed(points[idx]),
simmode_->getGlobalNedTransform().fromGlobalNed(points[idx+1]),
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a slight behavioural change here, index limit is decreased since earlier, it could crash when odd number of points are given
This fixes that, the last point will be ignored if odd no. of points are passed

@madratman madratman merged commit 1114607 into microsoft:master Sep 2, 2020
@rajat2004 rajat2004 deleted the plot-crash branch September 2, 2020 19:39
@rajat2004
Copy link
Contributor Author

Thanks for merging! Will try to add some scripts and docs as a future PR

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

Successfully merging this pull request may close these issues.

Bug: Using python's simPlotPoints (not too) many times sometimes crashes the Unreal Engine
2 participants