Why does UIaxes handle is deleted when calling a function and taking inputs as UIaxes handle in MATLAB webapp ?

5 次查看(过去 30 天)
Hello All,
I am facing one issue with taking UIaxes handle as input to the function.
I have created a Matlab WebApp where I plot about 20 different UIaxes plots and that I take these UiAxes to a report generator function and create a report of the same.
Issue is that when I call a report generator function it generates an error saying that
>> Error using matlab.ui.internal.preventMultiFigureAppsInWebAppServer/handleMultiWindowAttempt (line 27)
>> Web Apps does not support multiwindow apps.
>> Error using axes
>> Cannot set property to a deleted object.
>> Error in copyUIAxes (line 147)
>> Error in GenerateReport/checkaxistype (line 768)
>> Error in GenerateReport (line 99)
>> Error in App_GUI/GenerateReportButtonPushed (line 1490)
>> Error in appdesigner.internal.service.AppManagementService/tryCallback (line 189)
>> Error in matlab.apps.AppBase>@(source,event)tryCallback(appdesigner.internal.service.AppManagementService.instance(),app,callback,requiresEventData,event) (line 37)
>> Error using matlab.ui.control.internal.controller.ComponentController/executeUserCallback (line 427)
>> Error while evaluating Button PrivateButtonPushedFcn.
I tried to check the properties of the Axes which is being deleted just before calling this function. And it shows the properties which means those handles are not being deleted before calling the function. The properties are shown below.
>> UIAxes (Effort curve) with properties:
>> XLim: [0 137]
>> YLim: [0 9512]
>> XScale: 'linear'
>> YScale: 'linear'
>> GridLineStyle: '-'
>> Position: [153 245 509 434]
>> Units: 'pixels'
Use GET to show all properties
Any idea where I am going wrong. I have tried to copy obj to another object but same thing happens as above when calling a function.
To recreate this error I ahve attached the zip file which has the trail version of app and one report generating function and copyUIAxes fucntion. I have added the webapp file as well but this is for 2021b version only. The above error is from my actual code and the error you might get will a bit diffrent in terms of functions but main error is the same. "Web Apps does not support multiwindow apps." & "Cannot set property to a deleted object."
I am using matlab 2021b version.
Thankyou in advance!!

回答(3 个)

chicken vector
chicken vector 2023-11-28
It would be easier if you share your .mlapp file, but according to this line of error:
>> Web Apps does not support multiwindow apps.
The error may be that you are initialising multiple uifigure objects, which is not supported by AppDesigner.
The workaround is to initialise multiple apps.
Alternatively you can add two bottons to swiped across teh various uiaxes.
  3 个评论
chicken vector
chicken vector 2023-11-28
I find it very difficult to help you in this by only looking at error.
Could you try to replicate the app behaviour with a different .mlapp file?
Something simpler that you can share here, otherwise I can't do much.
Jay
Jay 2023-12-1
编辑:Jay 2023-12-1
I have created a trail version of the issue. I have attached to my question.
Error is the same but functions and figure properties are a bit diffrent.
I tried this app and this works fine in normal matlab app but in web app this create an error.
Let me know if you find a solution.

请先登录,再进行评论。


Voss
Voss 2023-12-1
copyUIAxes called with one input creates a new figure, as the comment near the top of copyUIAxes.m states:
% COPYUIAXES(uiax) creates a new figure and axis in default positions
% and copies the content of the UI axes onto the new axes.
However, creating a new figure is not supported by Web App Server, so you get the error, "Web Apps does not support multiwindow apps."
Try using the second input to copyUIAxes to specify the destination.
% COPYUIAXES(uiax,destination) copies the content of the UI axis to
% destination object which can either be a figure or axes handle. If
% the handle is a figure the axes will be created within the figure.
For example, you can try creating a new uiaxes to use as the destination to which your original uiaxes and its properties will be copied:
new_axes = uiaxes(app.RightPanel);
copyUIAxes(app.PoweratWheelsCurve, new_axes);
and then send the new uiaxes to the report generator function:
TrailApp_reportGenerate(app.PoweratWheelsCurve, new_axes)
I'm not sure about what the best parent is to create the new uiaxes in. Above I've used app.RightPanel because that's where the original uiaxes is.
Also, I'm not familiar with Report Generator, so I don't know what TrailApp_reportGenerate is supposed to do, but I suspect you'll run into the same error again on its line 45:
ax1 = copyUIAxes(axh);
  2 个评论
Jay
Jay 2023-12-1
Hello @Voss
I did not understand your answer as why we are plotting new axis as "app.RightPanel".
I will elaborate my reason to use copyUIaxes function is that earlier I was taking this UI axis handle to a report generate function where I complie them in to a report. So in this process I was converting UIaxes handle to report dom compilable "Axes Handle" and as result legend in the figure were missing out in report. Hence I came accross this function which lets you convert "UIaxes handle" to "figure Handle" which helped me to convert them to "Figure handle" (report generator format) which are used in report. And in this way I would not lose legends in the UIAxes figure.
Currenlty what I had put in code was both type of axes, first input is UIaxes and another is from copyUIaxes function. I thought might be a better to use copyUIaxes in app itself and then pass those axes to function but I still got the error.
function ax = checkaxistype(axh)
if strcmp(class(axh),'matlab.graphics.axis.Axes')
ax = Figure(axh);
elseif strcmp(class(axh),'matlab.ui.control.UIAxes')
ax1 = copyUIAxes(axh);
ax = Figure(ax1.figure);
else
error('Not Recognizable Axes Property')
end
end
This function was doing the thing. But this condition was there because I am using a script based version of this app also for faster checking. Hence the first condition is for script based axes and another was UIaxes. Script based axis have legend stored in them but in UIaxes those were a seperate class.
My problem is started after this when I convert this app to web app where these axis earlier I was using are open in another window just not visible. So I need a way around so that I can pass UIaxes handle to this function without acting as multiwindow figure. After this my report generation function will take care of the rest.
Voss
Voss 2023-12-1
"I did not understand your answer as why we are plotting new axis as "app.RightPanel"."
As I said, "Above I've used app.RightPanel because that's where the original uiaxes is."
Choose whatever parent for the new uiaxes that makes sense.
What happens when you run the adjusted code, i.e., call copyUIaxes with two inputs, the second one being a uiaxes you created directly?

请先登录,再进行评论。


Walter Roberson
Walter Roberson 2023-12-1
You are constructing your report by copying existing graphics object into a new uifigure that will act as the report holder.
When you use webapps you are limited to one uifigure -- so you cannot create a second uifigure to copy the graphics objects into.
You will need to create your report as a traditional figure (instead of as a uifigure) -- or else you will need to move things around and delete objects within your one single uifigure to create the report.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by