Warning: An error occurred while drawing the scene: Error in json_scenetree: Could not find node in replaceChild

My matlab version is 2020(a).
It always calls the "Warning: An error occurred while drawing the scene: Error in json_scenetree: Could not find node in replaceChild" .
I had try the previous solution "opengl software" , but it didn't work.
This is the code I complie.
Is the code have problem or matlab problem.
How can I deal with this problem?
clear all
close all
clc
ATT = 1;
DATE = datestr(now, 30);
mdl = 'quarter_car';
open_system(mdl)
agentblk = [mdl '/RL Agent'];
numObs = 5;
numAct = 2;
observationInfo = rlNumericSpec([numObs 1],'LowerLimit',-inf*ones(numObs,1),'UpperLimit',inf*ones(numObs,1));
observationInfo.Name = 'observation';
actionInfo = rlFiniteSetSpec({[0;0],[0;1]});
actionInfo.Name = 'actor';
env = rlSimulinkEnv(mdl,agentblk,observationInfo,actionInfo);
Ts = 0.01;
Tf = 10;
rng(0)
statePath = [
imageInputLayer([numObs 1 1],'Normalization','none','Name','observation')
fullyConnectedLayer(50,'Name','CriticObsFC1')
reluLayer('Name','CriticRelu1')
fullyConnectedLayer(30,'Name','CriticObsFC2')];
actionPath = [
imageInputLayer([numAct 1 1],'Normalization','none','Name','action')
fullyConnectedLayer(30,'Name','CriticActFC1')];
commonPath = [
additionLayer(2,'Name','add')
reluLayer('Name','CriticCommonRelu')
fullyConnectedLayer(1,'Name','output')];
criticNetwork = layerGraph(statePath);
criticNetwork = addLayers(criticNetwork,actionPath);
criticNetwork = addLayers(criticNetwork,commonPath);
criticNetwork = connectLayers(criticNetwork,'CriticObsFC2','add/in1');
criticNetwork = connectLayers(criticNetwork,'CriticActFC1','add/in2');
criticOpts = rlRepresentationOptions('LearnRate',0.001,'GradientThreshold',1);
obsInfo = getObservationInfo(env);
actInfo = getActionInfo(env);
critic = rlQValueRepresentation(criticNetwork,obsInfo,actInfo,'Observation',{'observation'},'Action',{'action'},criticOpts);
agentOptions = rlDQNAgentOptions(...
'SampleTime',Ts,...
'TargetSmoothFactor',1e-3,...
'ExperienceBufferLength',1e6,...
'UseDoubleDQN',false,...
'DiscountFactor',0.5,...
'MiniBatchSize',64);
agentOpts.NoiseOptions.Variance = 0.5;
agentOpts.NoiseOptions.VarianceDecayRate = 1e-3;
agent = rlDQNAgent(critic,agentOptions);
maxepisodes = 2000;
maxsteps = ceil(Tf/Ts);
trainingOptions = rlTrainingOptions(...
'MaxEpisodes',maxepisodes,...
'MaxStepsPerEpisode',maxsteps,...
'ScoreAveragingWindowLength',5,...
'Verbose',false,...
'Plots','training-progress',...
'StopTrainingCriteria','AverageReward',...
'StopTrainingValue', 25000);
trainingStats = train(agent,env,trainingOptions);
simOptions = rlSimulationOptions('MaxSteps', maxsteps);
experience = sim(env,agent,simOptions);

1 Commento

I have the same problem, but I am not usung simulink. I have just downloaded 2025b and I get this error usualy after re-sizing a figure. Does not occur in older versions

Accedi per commentare.

Risposte (3)

Ok, I narrowed it down the cause of the problem. The error occurs when using WebGL renderer which is the only option since 2025a onwards. The error occurs when any axis' xtick's (or maybe even other properties) are set to NaN. For example, with the following code I can recreate the error. The only thing is that the commands should be run one by one and not as a script.
f = figure;
aj = plot(1:5);
ax = gca;
ax.XTick = NaN;
set(ax,'Visible','off')
It would be helpful if the code threw an error when the XTick is set to NaN, rather than later when it is rendered, because there is no way to know which graphics object is causing the error.
Mayank
My suspicion is that the error does not have much to do with the code you are showing but with how you create your environment. It seems you are using Simulink here - are you plotting anything in your Simulink model? Maybe trying to visualize what is happening with your system? That's what I would check first.
I had the same error appear when trying to plot data that included NaNs. I had to restart matlab and get rid of the NaNs in my data. Then plot() worked.

Richiesto:

il 8 Gen 2021

Spostato:

il 16 Gen 2026

Community Treasure Hunt

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

Start Hunting!

Translated by